Hi!
I use hbm2ddl (from Hibernate Tools v3.2 beta 8) to create the DB schema and noticed, that non-existing or misspelled set properties are not detected.
Example :
mistype a String property :
<property name="pfoox" />
Result:
schema-export2:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/manning/hq/stein/data/Oseba.hbm.xml
[hibernatetool] org.hibernate.PropertyNotFoundException: field [pfoox] not found on com.manning.hq.stein.data.Oseba
But if I misspell a name of a set :
<set name="naslovxx">
<key />
<many-to-many class="Naslov"/>
</set>
no error is reported. It only fails at runtime in Configuration.buildSessionFactory().
Is this on purpose ? Seems strange to not detect and report this kind of errors.
My ant code is :
<path id="toolslib">
<!--path location="hib_tools/tools/hibernate-tools.jar" />
<path location="hib_tools/hibernate/hibernate3.jar" />
<path location="hib_tools/tools/freemarker.jar" /-->
<path location="${jdbc.driver.jar}" />
<pathelement location="src/java"/>
<path refid="project.classpath"/>
<pathelement location="../"/>
<fileset dir="hib_tools">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="schema-export2" depends="compile">
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib" />
<hibernatetool destdir="generated">
<configuration configurationfile="src/java/hibernate.cfg.xml"/>
<hbm2ddl export="true" drop="false" outputfilename="sql.ddl"/>
</hibernatetool>
</target
Hibernate version: 3.2
Mapping documents:
<set name="adresesx">
<key />
<many-to-many class="Address"/>
</set>
<property name="pfoox" />
Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.PropertyNotFoundException: Could not find a getter for naslovisa in class com.manning.hq.stein.data.Otrok
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:275)
at org.hibernate.mapping.Property.getGetter(Property.java:272)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:247)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:125)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:269)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:425)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:91)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:58)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1218)
at com.manning.hq.stein.Main2.persist_all(Main2.java:274)
at com.manning.hq.stein.Main2.main(Main2.java:40)
Name and version of the database you are using:
MySQL 4.1
Generated SQL(when typo in set name) :
create table Naslov (id bigint not null auto_increment, ulica varchar(255), his_st varchar(255), naselje varchar(255), post_st varchar(255), posta varchar(255), drzava varchar(255), vesoljskiNaslov bigint unique, primary key (id));
create table OdraslaOseba (OdraslaOseba bigint not null, poklic varchar(255), frend bigint, primary key (OdraslaOseba));
create table Oseba (id bigint not null auto_increment, ime varchar(255), priimek varchar(255), spol tinyblob, primary key (id));
create table Otrok (Otrok bigint not null, vzdevek varchar(255), primary key (Otrok));
create table VesoljskiNaslov (id bigint not null auto_increment, planet varchar(255), homeId bigint, primary key (id));
create table nasdsdlovisa (id bigint not null, elt bigint not null, primary key (id, elt));
alter table Naslov add index FK8AA6D253D353B1EF (vesoljskiNaslov), add constraint FK8AA6D253D353B1EF foreign key (vesoljskiNaslov) references VesoljskiNaslov (id);
alter table OdraslaOseba add index FK2527959C5DFEC075 (OdraslaOseba), add constraint FK2527959C5DFEC075 foreign key (OdraslaOseba) references Oseba (id);
alter table OdraslaOseba add index FK2527959C46B24768 (frend), add constraint FK2527959C46B24768 foreign key (frend) references Oseba (id);
alter table Otrok add index FK48FB5A9473234A2 (Otrok), add constraint FK48FB5A9473234A2 foreign key (Otrok) references Oseba (id);
alter table nasdsdlovisa add index FK736B1519D867DA27 (elt), add constraint FK736B1519D867DA27 foreign key (elt) references Naslov (id);
alter table nasdsdlovisa add index FK736B151940DF9BF4 (id), add constraint FK736B151940DF9BF4 foreign key (id) references Oseba (id);
|