Hello everyone,
I'm playing around with the latest Hibernate Tools 3.1.0beta2 in Eclipse 3.1.2 and Hibernate Annotations 3.1beta8.
I created a simple entity which I want to persist to a HSQLDB database. When I tell Hibernate Tools to do a SchemaExport by right-clicking on my Hibernate configuration in the "Hibernate Configurations" view the identity feature of my "id" column is not created. Inserting a NULL value for the id column should result in the database automatically assigning a value but it just complains that NULL values are not allowed for primary key columns which leads to the conclusion that the id column has not been created as identity.
On the other hand, when I create a Configuration object myself, pass it to a SchemaExport object and run the create(true,true) method on this SchemaExport object, everything works as expected. I therefore suspect a bug in the Hibernate Tools. Can anyone please confirm this or correct me if I'm wrong.
Thanks
Uli
Entity Java code (imports left out for brevity):
Code:
@Entity
@Table(name="test")
public class AnnoTestEntity {
public Integer id;
public String value;
public AnnoTestEntity(Integer id) {
this.id = id;
}
@Id
@GeneratedValue(generator="autoinc")
@GenericGenerator(name="autoinc", strategy="identity")
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
public String getValue() { return value; }
public void setValue(String value) { this.value = value; }
}
Hibernate configuration file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="HSQLTest">
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost/xdb</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<mapping class="test.hb.AnnoTestEntity"/>
</session-factory>
</hibernate-configuration>
Correctly working programmatic schema export (imports left out for brevity):
Code:
public class AnnoSchemaExport {
public static void main(String[] args) {
Configuration cfg = new AnnotationConfiguration().configure();
SchemaExport se = new SchemaExport(cfg);
se.create(true,true);
}
}
Hibernate log output for the correclty working schema export:
Code:
09:42:43,072 INFO Environment:479 - Hibernate 3.1.2
09:42:43,088 INFO Environment:509 - hibernate.properties not found
09:42:43,088 INFO Environment:525 - using CGLIB reflection optimizer
09:42:43,088 INFO Environment:555 - using JDK 1.4 java.sql.Timestamp handling
09:42:43,166 INFO Configuration:1308 - configuring from resource: /hibernate.cfg.xml
09:42:43,166 INFO Configuration:1285 - Configuration resource: /hibernate.cfg.xml
09:42:43,416 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd in classpath under org/hibernate/
09:42:43,416 DEBUG DTDEntityResolver:56 - found http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd in classpath
09:42:43,463 DEBUG Configuration:1269 - hibernate.connection.driver_class=org.hsqldb.jdbcDriver
09:42:43,463 DEBUG Configuration:1269 - hibernate.connection.url=jdbc:hsqldb:hsql://localhost/xdb
09:42:43,463 DEBUG Configuration:1269 - hibernate.dialect=org.hibernate.dialect.HSQLDialect
09:42:43,463 DEBUG AnnotationConfiguration:363 - HSQLTest<-org.dom4j.tree.DefaultAttribute@13582d [Attribute: name class value "test.hb.AnnoTestEntity"]
09:42:43,494 INFO Configuration:1419 - Configured SessionFactory: HSQLTest
09:42:43,510 DEBUG Configuration:1420 - properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, sun.boot.library.path=C:\Program Files\Java\jdk1.5.0_06\jre\bin, java.vm.version=1.5.0_06-b05, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=DE, sun.os.patch.level=Service Pack 2, java.vm.specification.name=Java Virtual Machine Specification, user.dir=D:\Data\Workspaces\hibernatetest, java.runtime.version=1.5.0_06-b05, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Program Files\Java\jdk1.5.0_06\jre\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\de1utd50\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, sun.jnu.encoding=Cp1252, java.library.path=C:\Program Files\Java\jdk1.5.0_06\bin;.;C:\WINNT\system32;C:\WINNT;C:\Program Files\CatPC\Bin;C:\Program Files\CatPC\Windows\System32;C:\Perl\bin\;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program Files\Subversion\bin;C:\Program Files\php-5.1.2-Win32;C:\mingw\bin;C:\msys\1.0\bin;C:\Program Files\gnuwin32\bin;C:\Program Files\MySQL\MySQL Server 5.0\bin;C:\Program Files\Java\jdk1.5.0_06\bin;C:\Program Files\IDM Computer Solutions\UltraEdit-32, java.specification.name=Java Platform API Specification, java.class.version=49.0, sun.management.compiler=HotSpot Client Compiler, os.version=5.1, user.home=C:\Documents and Settings\de1utd50, user.timezone=Europe/Berlin, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.5, hibernate.connection.driver_class=org.hsqldb.jdbcDriver, user.name=de1utd50, java.class.path=D:\Data\Workspaces\hibernatetest\bin;D:\Data\Workspaces\hibernatetest\lib\hsqldb.jar;C:\Program Files\Java\xdoclet-1.2.3\lib\xdoclet-hibernate-module-1.2.3.jar;C:\Program Files\Java\hibernate-3.1\lib\ant-1.6.5.jar;C:\Program Files\Java\hibernate-3.1\lib\ant-antlr-1.6.5.jar;C:\Program Files\Java\hibernate-3.1\lib\ant-junit-1.6.5.jar;C:\Program Files\Java\hibernate-3.1\lib\ant-launcher-1.6.5.jar;C:\Program Files\Java\hibernate-3.1\lib\antlr-2.7.6rc1.jar;C:\Program Files\Java\hibernate-3.1\lib\ant-swing-1.6.5.jar;C:\Program Files\Java\hibernate-3.1\lib\asm.jar;C:\Program Files\Java\hibernate-3.1\lib\asm-attrs.jar;C:\Program Files\Java\hibernate-3.1\lib\c3p0-0.9.0.jar;C:\Program Files\Java\hibernate-3.1\lib\cglib-2.1.3.jar;C:\Program Files\Java\hibernate-3.1\lib\cleanimports.jar;C:\Program Files\Java\hibernate-3.1\lib\commons-collections-2.1.1.jar;C:\Program Files\Java\hibernate-3.1\lib\commons-logging-1.0.4.jar;C:\Program Files\Java\hibernate-3.1\lib\concurrent-1.3.2.jar;C:\Program Files\Java\hibernate-3.1\lib\connector.jar;C:\Program Files\Java\hibernate-3.1\lib\dom4j-1.6.1.jar;C:\Program Files\Java\hibernate-3.1\lib\ehcache-1.1.jar;C:\Program Files\Java\hibernate-3.1\lib\jaas.jar;C:\Program Files\Java\hibernate-3.1\lib\jacc-1_0-fr.jar;C:\Program Files\Java\hibernate-3.1\lib\jaxen-1.1-beta-7.jar;C:\Program Files\Java\hibernate-3.1\lib\jboss-cache.jar;C:\Program Files\Java\hibernate-3.1\lib\jboss-common.jar;C:\Program Files\Java\hibernate-3.1\lib\jboss-jmx.jar;C:\Program Files\Java\hibernate-3.1\lib\jboss-system.jar;C:\Program Files\Java\hibernate-3.1\lib\jdbc2_0-stdext.jar;C:\Program Files\Java\hibernate-3.1\lib\jgroups-2.2.8.jar;C:\Program Files\Java\hibernate-3.1\lib\jta.jar;C:\Program Files\Java\hibernate-3.1\lib\junit-3.8.1.jar;C:\Program Files\Java\hibernate-3.1\lib\log4j-1.2.11.jar;C:\Program Files\Java\hibernate-3.1\lib\oscache-2.1.jar;C:\Program Files\Java\hibernate-3.1\lib\proxool-0.8.3.jar;C:\Program Files\Java\hibernate-3.1\lib\swarmcache-1.0rc2.jar;C:\Program Files\Java\hibernate-3.1\lib\syndiag2.jar;C:\Program Files\Java\hibernate-3.1\lib\versioncheck.jar;C:\Program Files\Java\hibernate-3.1\lib\xerces-2.6.2.jar;C:\Program Files\Java\hibernate-3.1\lib\xml-apis.jar;C:\Program Files\Java\hibernate-3.1\hibernate3.jar;C:\Program Files\Java\hibernate-annotations-3.1beta8\hibernate-annotations.jar;C:\Program Files\Java\hibernate-annotations-3.1beta8\lib\ejb3-persistence.jar;D:\Data\Workspaces\hibernatetest\lib, java.vm.specification.version=1.0, java.home=C:\Program Files\Java\jdk1.5.0_06\jre, sun.arch.data.model=32, hibernate.dialect=org.hibernate.dialect.HSQLDialect, hibernate.connection.url=jdbc:hsqldb:hsql://localhost/xdb, user.language=de, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, sharing, java.version=1.5.0_06, java.ext.dirs=C:\Program Files\Java\jdk1.5.0_06\jre\lib\ext, sun.boot.class.path=C:\Program Files\Java\jdk1.5.0_06\jre\lib\rt.jar;C:\Program Files\Java\jdk1.5.0_06\jre\lib\i18n.jar;C:\Program Files\Java\jdk1.5.0_06\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.5.0_06\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.5.0_06\jre\lib\jce.jar;C:\Program Files\Java\jdk1.5.0_06\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.5.0_06\jre\classes, java.vendor=Sun Microsystems Inc., file.separator=\, hibernate.session_factory_name=HSQLTest, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, sun.cpu.isalist=}
09:42:43,526 INFO Dialect:103 - Using dialect: org.hibernate.dialect.HSQLDialect
09:42:43,635 DEBUG AnnotationConfiguration:200 - Execute first pass mapping processing
09:42:43,635 DEBUG AnnotationConfiguration:259 - Process hbm files
09:42:43,635 DEBUG AnnotationConfiguration:267 - Process annotated classes
09:42:43,682 INFO AnnotationBinder:322 - Binding entity from annotated class: test.hb.AnnoTestEntity
09:42:43,698 DEBUG Ejb3Column:160 - Binding column TYPE unique false
09:42:43,713 DEBUG EntityBinder:203 - Import with entity name=AnnoTestEntity
09:42:43,729 INFO EntityBinder:300 - Bind entity test.hb.AnnoTestEntity on table test
09:42:43,729 DEBUG AnnotationBinder:862 - Processing test.hb.AnnoTestEntity per property annotation
09:42:43,760 DEBUG AnnotationBinder:931 - Processing annotations of test.hb.AnnoTestEntity.id
09:42:43,760 DEBUG Ejb3Column:160 - Binding column id unique false
09:42:43,760 DEBUG AnnotationBinder:1044 - id is an id
09:42:43,776 DEBUG AnnotationBinder:290 - Add generic generator with name: autoinc
09:42:43,776 DEBUG SimpleValueBinder:186 - building SimpleValue for id
09:42:43,776 DEBUG PropertyBinder:112 - Building property id
09:42:43,791 DEBUG PropertyBinder:121 - Cascading id with null
09:42:43,791 DEBUG AnnotationBinder:1081 - Bind @Id on id
09:42:43,791 DEBUG AnnotationBinder:931 - Processing annotations of test.hb.AnnoTestEntity.value
09:42:43,791 DEBUG Ejb3Column:160 - Binding column value unique false
09:42:43,791 DEBUG PropertyBinder:93 - binding property value with lazy=false
09:42:43,791 DEBUG SimpleValueBinder:186 - building SimpleValue for value
09:42:43,791 DEBUG PropertyBinder:112 - Building property value
09:42:43,791 DEBUG PropertyBinder:121 - Cascading value with null
09:42:43,807 DEBUG ClassValidator:93 - ResourceBundle ValidatorMessages not found. Delegate to org.hibernate.validator.resources.DefaultValidatorMessages
09:42:43,807 DEBUG AnnotationConfiguration:227 - processing manytoone fk mappings
09:42:43,807 DEBUG Configuration:1002 - processing extends queue
09:42:43,807 DEBUG Configuration:1006 - processing collection mappings
09:42:43,807 DEBUG Configuration:1017 - processing native query and ResultSetMapping mappings
09:42:43,807 DEBUG Configuration:1025 - processing association property references
09:42:43,807 DEBUG Configuration:1047 - processing foreign key constraints
09:42:43,885 DEBUG AnnotationConfiguration:200 - Execute first pass mapping processing
09:42:43,885 DEBUG AnnotationConfiguration:259 - Process hbm files
09:42:43,885 DEBUG AnnotationConfiguration:267 - Process annotated classes
09:42:43,885 DEBUG AnnotationConfiguration:227 - processing manytoone fk mappings
09:42:43,885 DEBUG Configuration:1002 - processing extends queue
09:42:43,885 DEBUG Configuration:1006 - processing collection mappings
09:42:43,885 DEBUG Configuration:1017 - processing native query and ResultSetMapping mappings
09:42:43,885 DEBUG Configuration:1025 - processing association property references
09:42:43,885 DEBUG Configuration:1047 - processing foreign key constraints
09:42:43,885 INFO SchemaExport:155 - Running hbm2ddl schema export
09:42:43,885 DEBUG SchemaExport:173 - import file not found: /import.sql
09:42:43,885 INFO SchemaExport:182 - exporting generated schema to database
09:42:43,901 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
09:42:43,901 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
09:42:43,901 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
09:42:43,901 INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost/xdb
09:42:43,901 INFO DriverManagerConnectionProvider:83 - connection properties: {}
09:42:43,901 DEBUG DriverManagerConnectionProvider:93 - total checked-out connections: 0
09:42:43,901 DEBUG DriverManagerConnectionProvider:109 - opening new JDBC connection
09:42:43,994 DEBUG DriverManagerConnectionProvider:115 - created connection to: jdbc:hsqldb:hsql://localhost/xdb, Isolation Level: 0
drop table test if exists
09:42:43,994 DEBUG SchemaExport:296 - drop table test if exists
create table test (id integer generated by default as identity (start with 1), value varchar(255), primary key (id))
09:42:43,994 DEBUG SchemaExport:296 - create table test (id integer generated by default as identity (start with 1), value varchar(255), primary key (id))
09:42:43,994 INFO SchemaExport:202 - schema export complete
09:42:43,994 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
09:42:43,994 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:hsqldb:hsql://localhost/xdb
Excerpt from Eclipse log from the time around my tryings:
Code:
!ENTRY org.hibernate.eclipse 2 30000 2006-03-22 09:44:01.476
!MESSAGE WARN Worker-25 org.hibernate.impl.SessionFactoryObjectFactory - Could not bind factory to JNDI
!STACK 0
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getNameParser(Unknown Source)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:290)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1154)
at org.hibernate.console.ConsoleConfiguration$2.execute(ConsoleConfiguration.java:265)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:35)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:68)
at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:260)
at org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter.getChildren(ConsoleConfigurationWorkbenchAdapter.java:24)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:70)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:192)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:76)
!ENTRY org.hibernate.eclipse 2 30000 2006-03-22 09:44:11.884
!MESSAGE WARN main org.hibernate.impl.SessionFactoryObjectFactory - Could not unbind factory from JNDI
!STACK 0
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.unbind(Unknown Source)
at org.hibernate.impl.SessionFactoryObjectFactory.removeInstance(SessionFactoryObjectFactory.java:116)
at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:760)
at org.hibernate.console.ConsoleConfiguration.closeSessionFactory(ConsoleConfiguration.java:368)
at org.hibernate.console.ConsoleConfiguration.reset(ConsoleConfiguration.java:82)
at org.hibernate.eclipse.console.actions.BuildSessionFactoryAction.doRun(BuildSessionFactoryAction.java:35)
at org.hibernate.eclipse.console.actions.ConsoleConfigurationBasedAction.run(ConsoleConfigurationBasedAction.java:46)
at org.eclipse.ui.actions.BaseSelectionListenerAction.runWithEvent(BaseSelectionListenerAction.java:167)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:538)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:488)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:400)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:843)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3125)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2758)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1699)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:367)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:226)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:334)
at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
at org.eclipse.core.launcher.Main.run(Main.java:973)
at org.eclipse.core.launcher.Main.main(Main.java:948)
!ENTRY org.hibernate.eclipse 2 30000 2006-03-22 09:44:12.853
!MESSAGE WARN Worker-26 org.hibernate.impl.SessionFactoryObjectFactory - Could not bind factory to JNDI
!STACK 0
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getNameParser(Unknown Source)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:290)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1154)
at org.hibernate.console.ConsoleConfiguration$2.execute(ConsoleConfiguration.java:265)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:35)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:68)
at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:260)
at org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter.getChildren(ConsoleConfigurationWorkbenchAdapter.java:24)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:70)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:192)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:76)
!ENTRY org.hibernate.eclipse 4 40000 2006-03-22 09:44:17.541
!MESSAGE ERROR main org.hibernate.hql.PARSER - <AST>:0:0: unexpected end of subtree
Hibernate version: 3.1.2
Mapping documents:none
Code between sessionFactory.openSession() and session.close():none
Full stack trace of any exception that occurs:none
Name and version of the database you are using:HSQLDB 1.8.0_2
The generated SQL (show_sql=true):not applicable
Debug level Hibernate log excerpt:not applicable[/code]