Hi there,
i m new to Spring, and also Hibernate Annotations -_-
i m writing a very simple example to see how it interacts with the DB. But i m so frustrated because i couldn't get it work properly, if i take off the (at)Entity from the JavaBean class, it runs ok, but nothing done to the DB, if i add (at)Entity in, it crashes at some stage, no change to DB either. Here's my code, please help me, i've been trying this for 2 days already, so sad ...Here's my spring context XML
Sorry i have to user (at) to replace all the 'at' symbol, otherwise it won't post.
this is the Hibernate mapping fileCode:... ... <beans> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/hibernate_tut" /> <property name="username" value="test" /> <property name="password" value="test" /> </bean> <!-- Hibernate session factory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="configLocation"> <value>hibernate.cfg.xml</value> </property> <property name="configurationClass"> <value>org.hibernate.cfg.AnnotationConfiguration</value> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLInnoDBDialect </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> </beans>
This is the JavaBeanCode:............ <hibernate-configuration> <session-factory> <mapping class="au.com.hibernatetest.model.Client"/> </session-factory> </hibernate-configuration>
and the Test.javaCode:package au.com.hibernatetest.model; import java.io.Serializable; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; (at)Entity // --------------------------- without this, it runs, but no DB change, with this, crashes (at)Table(name="hb_client") public class Client implements Serializable { /** * */ private static final long serialVersionUID = 7827154723198058789L; private Long pkId; private Date lastUpdated; private String username; private String password; (at)Id (at)Column(name = "pk_client_id") (at)GeneratedValue(strategy = GenerationType.AUTO) public Long getPkId() { return pkId; } public void setPkId(Long pkId) { this.pkId = pkId; } public Date getLastUpdated() { return lastUpdated; } public void setLastUpdated(Date lastUpdated) { this.lastUpdated = lastUpdated; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
I use Maven2 to compile it, and run the Test.java. I suppose it should add a table into the DB when i run it.Code:package au.com.hibernatetest.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test { private static ApplicationContext ctx = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); public static void main(String args[]) { try{ Test test = new Test(); }catch(Exception ex) { ex.printStackTrace(); } } }
Thank you very much for the help, i'll be looking forward to your reply!!!!!


Reply With Quote