For a weekend project I was trying to run JPA 2 with Hibernate 3.5. Please note that I am not getting any compile errors or runtime exceptions (when I deploy the war on Tomcat). Below is my code -
persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="postage" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"></property>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/postage"></property>
<property name="hibernate.connection.username" value="postage"></property>
<property name="hibernate.connection.password" value="postage"></property>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"></property>
<property name="hibernate.hbm2ddl.auto" value="create-drop"></property>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml"></property>
</properties>
</persistence-unit>
</persistence>
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="current_session_context_class">thread</property>
<!-- mapping files -->
<mapping class="net.rocky.postage.domain.Post"/>
<mapping class="net.rocky.postage.domain.User"/>
</session-factory>
</hibernate-configuration>
I have 2 simple Entity classes -
@Entity
@Table(name="Post")
public class Post implements Serializable{
@Id
@GeneratedValue
private long id;
private String description;
private String comments;
@OneToOne
private User postedBy;
And
@Entity
@Table(name="PostageUser")
public class User implements Serializable{
@Id
@GeneratedValue
private long id;
private String username;
private String password;
Am I missing something here. I have spent my whole saturday trying all combinations. Please help me.
Follow-up 1: By not working I mean - When I deploy the app on Tomcat, I do not see 2 tables created in Postgres (as I have given create-drop in hbm2ddl).
Follow-up 2: Thanks for your response. I cannot even get Hibernate to log messages. Here is my config:
log4j.appender.S=org.apache.log4j.ConsoleAppender
log4j.appender.S.layout=org.apache.log4j.PatternLayout
log4j.appender.S.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
log4j.rootCategory=DEBUG, S
Also, in maven I have added -
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
still no log messages from hibernate