Hi,
I am using the hbm2java Ant task to generate the POJOs. Unfortunatelly
the ID's getter and setter is not generated. I assume we don't require a <property>
for this.
I suspect my set-up/configration may be to blame. Specifically, I see that when
hbm2java executes, it always seems to try and load te properties file independent
of the XML configuration file.
Hibernate version:
Hibernate 3.0
Hibernate tools 3.0 alpha
Mapping documents:
Class mappiing
..........................
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="pt">
<class
name="Child"
table="browser.actor"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
where="g1='R' AND g2='W'"
>
<id
name="id"
column="idactor"
type="long"
>
<generator class="sequence">
<param name="sequence">idactor_seq</param>
</generator>
</id>
<property
name="name"
type="string"
update="true"
insert="true"
access="property"
column="nameac"
/>
<property
name="email"
type="string"
update="true"
insert="true"
access="property"
column="email"
/>
<property
name="address"
type="string"
update="true"
insert="true"
access="property"
column="address"
/>
<!-- many-to-one
name="accommodationType"
class="Parent"
cascade="save-update"
outer-join="auto"
update="true"
insert="true"
access="property"
column="typela"
not-null="true"
/ -->
</class>
</hibernate-mapping>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
HBM2Java Configuation file
.............................................
<hibernate-configuration>
<session-factory name="linkall">
<!-- properties -->
<property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<property name="connection.username">hugof</property>
<property name="connection.driver_class">org.postgresql.jdbc2.optional.PoolingDataSource</property>
<property name="connection.url">jdbc:postgresql://localhost/browser</property>
<!-- mapping files -->
<mapping resource="pt/Child.hbm.xml"/>
<mapping resource="pt/Parent.hbm.xml"/>
</session-factory>
<codegen>
<generate renderer="org.hibernate.tool.hbm2java.BasicRenderer">
<param name="generate-concrete-empty-classes">false</param>
</generate>
<generate
package="autofinders.only"
suffix="Finder"
renderer="org.hibernate.tool.hbm2java.FinderRenderer"/>
</codegen>
</hibernate-configuration>
Ant Task
.................
<target name="generatesources">
<taskdef name="generatesources"
classname="org.hibernate.tool.hbm2java.Hbm2JavaTask"
classpathref="hibernate.classpath">
</taskdef>
<generatesources config="${src}/hbm2java.cfg.xml"
output="${src}"
>
<fileset dir="${src}">
<include name="pt/**/*.hbm.xml" />
</fileset>
</generatesources>
</target>
Code between sessionFactory.openSession() and session.close():
None
Full stack trace of any exception that occurs:
org.hibernate.PropertyNotFoundException: Could not find a getter for id in class pt.Child
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:213)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:207)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:148)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:41)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:104)
at org.hibernate.persister.entity.BasicEntityPersister.<init>(BasicEntityPersister.java:398)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:104)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:199)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043)
at Test.testCreateActor(Test.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at junit.textui.TestRunner.run(TestRunner.java:72)
at junit.textui.TestRunner.run(TestRunner.java:57)
at Test.main(Test.java:39)
Name and version of the database you are using:
PostgreSQL 7.4
The generated SQL (show_sql=true):
none
Debug level Hibernate log excerpt:
generatesources:
[generatesources] Processing 2 files.
[generatesources] Building hibernate objects
[generatesources] 13 Mar 2005 17:20:11.171 [DEBUG] [main] [org.hibernate.util.DTDEntityResolver] - trying to locate
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hibernate/
[generatesources] 13 Mar 2005 17:20:11.175 [DEBUG] [main] [org.hibernate.util.DTDEntityResolver] - found
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
[generatesources] 13 Mar 2005 17:20:11.293 [INFO] [main] [org.hibernate.cfg.Environment] - Hibernate 3.0rc1
[generatesources] 13 Mar 2005 17:20:11.296 [INFO] [main] [org.hibernate.cfg.Environment] - hibernate.properties not found
[generatesources] 13 Mar 2005 17:20:11.300 [INFO] [main] [org.hibernate.cfg.Environment] - using CGLIB reflection optimizer
[generatesources] 13 Mar 2005 17:20:11.304 [INFO] [main] [org.hibernate.cfg.Environment] - using JDK 1.4 java.sql.Timestamp handling
[generatesources] 13 Mar 2005 17:20:11.306 [INFO] [main] [org.hibernate.cfg.Configuration] - Mapping file: /home/hugof/workspace/hiber3/src/pt/Child.hbm.xml
[generatesources] 13 Mar 2005 17:20:11.427 [DEBUG] [main] [org.hibernate.util.DTDEntityResolver] - trying to locate
http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath under org/hibernate/
[generatesources] 13 Mar 2005 17:20:11.430 [DEBUG] [main] [org.hibernate.util.DTDEntityResolver] - found
http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath
[generatesources] 13 Mar 2005 17:20:11.684 [INFO] [main] [org.hibernate.cfg.HbmBinder] - Mapping class: pt.Child -> browser.actor
[generatesources] 13 Mar 2005 17:20:11.696 [DEBUG] [main] [org.hibernate.cfg.HbmBinder] - Mapped property: id -> idactor
[generatesources] 13 Mar 2005 17:20:11.723 [DEBUG] [main] [org.hibernate.cfg.HbmBinder] - Mapped property: name -> nameac
[generatesources] 13 Mar 2005 17:20:11.727 [DEBUG] [main] [org.hibernate.cfg.HbmBinder] - Mapped property: email -> email
[generatesources] 13 Mar 2005 17:20:11.728 [DEBUG] [main] [org.hibernate.cfg.HbmBinder] - Mapped property: address -> address
[generatesources] 13 Mar 2005 17:20:11.730 [INFO] [main] [org.hibernate.cfg.Configuration] - processing extends queue
[generatesources] 13 Mar 2005 17:20:11.731 [INFO] [main] [org.hibernate.cfg.Configuration] - processing collection mappings
[generatesources] 13 Mar 2005 17:20:11.732 [INFO] [main] [org.hibernate.cfg.Configuration] - processing association property references
[generatesources] 13 Mar 2005 17:20:11.736 [INFO] [main] [org.hibernate.cfg.Configuration] - processing foreign key constraints
[generatesources] 13 Mar 2005 17:20:11.742 [DEBUG] [main] [org.hibernate.tool.hbm2java.ClassMapping] - Processing mapping for class: pt.Child
[generatesources] 13 Mar 2005 17:20:11.768 [INFO] [main] [org.hibernate.tool.hbm2java.FieldProperty] - fieldname = name
[generatesources] 13 Mar 2005 17:20:11.924 [INFO] [main] [org.hibernate.tool.hbm2java.FieldProperty] - fieldname = email
[generatesources] 13 Mar 2005 17:20:11.925 [INFO] [main] [org.hibernate.tool.hbm2java.FieldProperty] - fieldname = address
[generatesources] 13 Mar 2005 17:20:11.927 [INFO] [main] [org.hibernate.tool.hbm2java.Generator] - Generating 1 in /home/hugof/workspace/hiber3/src
[generatesources] 13 Mar 2005 17:20:11.964 [DEBUG] [main] [org.hibernate.tool.hbm2java.Generator] - Writing /home/hugof/workspace/hiber3/src/pt/Child.java
[generatesources] 13 Mar 2005 17:20:11.979 [DEBUG] [main] [org.hibernate.util.DTDEntityResolver] - trying to locate
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hibernate/
[generatesources] 13 Mar 2005 17:20:11.982 [DEBUG] [main] [org.hibernate.util.DTDEntityResolver] - found
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
[generatesources] 13 Mar 2005 17:20:11.990 [INFO] [main] [org.hibernate.cfg.Configuration] - Mapping file: /home/hugof/workspace/hiber3/src/pt/Parent.hbm.xml
[generatesources] 13 Mar 2005 17:20:11.993 [DEBUG] [main] [org.hibernate.util.DTDEntityResolver] - trying to locate
http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath under org/hibernate/
[generatesources] 13 Mar 2005 17:20:11.995 [DEBUG] [main] [org.hibernate.util.DTDEntityResolver] - found
http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath
[generatesources] 13 Mar 2005 17:20:12.029 [INFO] [main] [org.hibernate.cfg.HbmBinder] - Mapping class: pt.Parent -> browser.typelocalactor
[generatesources] 13 Mar 2005 17:20:12.032 [DEBUG] [main] [org.hibernate.cfg.HbmBinder] - Mapped property: id -> idtla
[generatesources] 13 Mar 2005 17:20:12.033 [DEBUG] [main] [org.hibernate.cfg.HbmBinder] - Mapped property: name -> nametla
[generatesources] 13 Mar 2005 17:20:12.035 [DEBUG] [main] [org.hibernate.cfg.HbmBinder] - Mapped property: description -> desctla
[generatesources] 13 Mar 2005 17:20:12.036 [INFO] [main] [org.hibernate.cfg.Configuration] - processing extends queue
[generatesources] 13 Mar 2005 17:20:12.037 [INFO] [main] [org.hibernate.cfg.Configuration] - processing collection mappings
[generatesources] 13 Mar 2005 17:20:12.039 [INFO] [main] [org.hibernate.cfg.Configuration] - processing association property references
[generatesources] 13 Mar 2005 17:20:12.041 [INFO] [main] [org.hibernate.cfg.Configuration] - processing foreign key constraints
[generatesources] 13 Mar 2005 17:20:12.045 [DEBUG] [main] [org.hibernate.tool.hbm2java.ClassMapping] - Processing mapping for class: pt.Parent
[generatesources] 13 Mar 2005 17:20:12.046 [INFO] [main] [org.hibernate.tool.hbm2java.FieldProperty] - fieldname = name
[generatesources] 13 Mar 2005 17:20:12.050 [INFO] [main] [org.hibernate.tool.hbm2java.FieldProperty] - fieldname = description
[generatesources] 13 Mar 2005 17:20:12.095 [INFO] [main] [org.hibernate.tool.hbm2java.Generator] - Generating 1 in /home/hugof/workspace/hiber3/src
[generatesources] 13 Mar 2005 17:20:12.097 [DEBUG] [main] [org.hibernate.tool.hbm2java.Generator] - Writing /home/hugof/workspace/hiber3/src/pt/Parent.java
BUILD SUCCESSFUL
Total time: 2 seconds
Please note that when generating I have the output:
[INFO] [main] [org.hibernate.cfg.HbmBinder] - Mapping class: pt.Child -> browser.actor
[generatesources] 13 Mar 2005 17:20:11.696 [DEBUG] [main] [org.hibernate.cfg.HbmBinder] - Mapped property: id -> idactor
Which indicates that the id is in fact read.
Appreciate any pointers.
TIA,
Hugo Ferreira.