Hibernate does not create Table in the database -
i using postgresql
, trying run simple hibernate
application, in particular application decribed in page. hibernate.cfg.xml file is:
<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd 3.0//en" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">org.postgresql.driver</property> <property name="hibernate.connection.url">jdbc:postgresql:testdb2</property> <property name="hibernate.dialect">org.hibernate.dialect.postgresqldialect</property> <property name="hibernate.connection.username">postgres</property> <property name="hibernate.connection.password">user</property> <property name="connection.pool_size">1</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.hbm2dll.auto">create</property> <property name="current_session_context_class">thread</property> <property name="cache.provider_class">org.hibernate.cache.nocacheprovider</property> <!-- <property name="transaction.factory_class">org.hibernate.transaction.jdbctransactionfactory</property> --> <mapping class="com.al.hibmaventest.department"/> <mapping class="com.al.hibmaventest.employee"/> </session-factory> </hibernate-configuration>
my pom.xml
(when using maven) is:
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.al.hibmaventest</groupid> <artifactid>hibmaventest</artifactid> <version>0.0.1-snapshot</version> <dependencies> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate</artifactid> <version>3.2.6.ga</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-annotations</artifactid> <version>3.3.1.ga</version> </dependency> <dependency> <groupid>postgresql</groupid> <artifactid>postgresql</artifactid> <version>9.1-901.jdbc4</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build> </project>
i use main()
in link:
public static void main(string[] args) { sessionfactory sf = hibernateutil.getsessionfactory(); session session = sf.opensession(); session.begintransaction(); department department = new department(); department.setdepartmentname("sales"); session.persist(department); employee emp1 = new employee("nina", "mayers", "111"); employee emp2 = new employee("tony", "almeida", "222"); emp1.setdepartment(department); emp2.setdepartment(department); session.persist(emp1); session.persist(emp2); session.gettransaction().commit(); session.close(); }
however impossible application work, namely hibernate create tables in database , insert value. receive always, whatever tried, same error:
info: not binding factory jndi, no jndi name configured hibernate: insert department (dept_name) values (?) mai 19, 2013 6:56:49 pm org.hibernate.util.jdbcexceptionreporter logexceptions warning: sql error: 0, sqlstate: 42p01 mai 19, 2013 6:56:49 pm org.hibernate.util.jdbcexceptionreporter logexceptions severe: error: relation "department" not exist position: 13 exception in thread "main" org.hibernate.exception.sqlgrammarexception: not insert: [com.al.hibmaventest.department] @ org.hibernate.exception.sqlstateconverter.convert(sqlstateconverter.java:67) @ org.hibernate.exception.jdbcexceptionhelper.convert(jdbcexceptionhelper.java:43) @ org.hibernate.id.insert.abstractreturningdelegate.performinsert(abstractreturningdelegate.java:40) @ org.hibernate.persister.entity.abstractentitypersister.insert(abstractentitypersister.java:2163) @ org.hibernate.persister.entity.abstractentitypersister.insert(abstractentitypersister.java:2643) @ org.hibernate.action.entityidentityinsertaction.execute(entityidentityinsertaction.java:51) @ org.hibernate.engine.actionqueue.execute(actionqueue.java:279) @ org.hibernate.event.def.abstractsaveeventlistener.performsaveorreplicate(abstractsaveeventlistener.java:298) @ org.hibernate.event.def.abstractsaveeventlistener.performsave(abstractsaveeventlistener.java:181) @ org.hibernate.event.def.abstractsaveeventlistener.savewithgeneratedid(abstractsaveeventlistener.java:107) @ org.hibernate.event.def.defaultpersisteventlistener.entityistransient(defaultpersisteventlistener.java:131) @ org.hibernate.event.def.defaultpersisteventlistener.onpersist(defaultpersisteventlistener.java:87) @ org.hibernate.event.def.defaultpersisteventlistener.onpersist(defaultpersisteventlistener.java:38) @ org.hibernate.impl.sessionimpl.firepersist(sessionimpl.java:618) @ org.hibernate.impl.sessionimpl.persist(sessionimpl.java:592) @ org.hibernate.impl.sessionimpl.persist(sessionimpl.java:596) @ com.al.hibmaventest.main.main(main.java:25) caused by: org.postgresql.util.psqlexception: error: relation "department" not exist position: 13 @ org.postgresql.core.v3.queryexecutorimpl.receiveerrorresponse(queryexecutorimpl.java:2102) @ org.postgresql.core.v3.queryexecutorimpl.processresults(queryexecutorimpl.java:1835) @ org.postgresql.core.v3.queryexecutorimpl.execute(queryexecutorimpl.java:257) @ org.postgresql.jdbc2.abstractjdbc2statement.execute(abstractjdbc2statement.java:500) @ org.postgresql.jdbc2.abstractjdbc2statement.executewithflags(abstractjdbc2statement.java:388) @ org.postgresql.jdbc2.abstractjdbc2statement.executeupdate(abstractjdbc2statement.java:334) @ org.hibernate.id.identitygenerator$getgeneratedkeysdelegate.executeandextract(identitygenerator.java:73) @ org.hibernate.id.insert.abstractreturningdelegate.performinsert(abstractreturningdelegate.java:33) ... 14 more
"relation department not exist" on line :
session.persist(department);
i have tried without maven
well, same error. in order preempt readers, table (relation) "department" never created in database. if create manually in database(what hibernate expected do), error remains same. think problem in creation of sessions or in connection withe database.
does postgresql
need configuration accept hibernate
connection?. can problem come jndi
message says "not binding factory jndi, no jndi name configured"?
any suggestions?
the property hibernate.hbm2ddl.auto
, instead of hibernate.hbm2dll.auto
.
ddl = data definition language
dll = dynamically loaded library
Comments
Post a Comment