-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Wrong set name not detected by hbm2ddl
PostPosted: Mon Nov 06, 2006 10:00 am 
Regular
Regular

Joined: Thu Oct 19, 2006 12:07 pm
Posts: 75
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);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 10:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
The error occurs because hibernate needs to known the type of the property during the Configuration building/usage phase.

We don't need to use reflection to decide the type of the set, thus we don't fail here.

When building the SessionFactory we need the actual classes; and thus it will fail.

So why don't we add a property name check into Configuration ?

A couple of reasons:

1) you don't need classes to use hibernate (dom4j, map, ... entitymode)

2) hbm2java would not be able to run if Configuration required classes.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.