-->
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.  [ 6 posts ] 
Author Message
 Post subject: Mapping Exception with missing id
PostPosted: Mon Sep 01, 2003 5:44 pm 
Newbie

Joined: Mon Sep 01, 2003 5:34 pm
Posts: 4
Hello
My question is regarding the <id> element in the <class> declarion in the mapping file. My understanding from reading the reference manual is that the id name is optional. So I have the following declarion in the mapping file:

Code:
<class "testdb2.Department" table="department">
  <id>
    <generator class="identity"/>
  </id>
  ...
</class>


The Department java class is the one given in the external documentation example from IBM, minus of course the DepartmentID element.

However, when I run this through the schema generator I get the following error message:

Sep 1, 2003 4:25:02 PM net.sf.hibernate.cfg.Configuration add
SEVERE: Could not compile the mapping document
net.sf.hibernate.MappingException: must specify an identifier type: testdb2.Department
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:218)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1094)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:230)
at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:155)
at net.sf.hibernate.tool.hbm2ddl.SchemaExport.main(SchemaExport.java:285)

(When I reinstate the <id> attributes, then it runs through fine)

Can anyone offer any insight?

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 6:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The id name is optional only if you want no identitier property. I would STRONGLY recommend that you use an identifier property, however.


The exception is really quite self-explanatory: you did not specify an identifier type.


Obviously, if you don't specify an id property, you need to be explicit with the id type attribute.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 2:05 pm 
Newbie

Joined: Mon Sep 01, 2003 5:34 pm
Posts: 4
Quote:
Obviously, if you don't specify an id property, you need to be explicit with the id type attribute.

Well...strictly speaking it ought not to be required if Hibernate is managing the keys it could choose whatever column type and generation strategy it wants, defaulting to int and increment if necc...but that's a silly quibble I suppose

BTW, a more serious problem is that I can't seem to get anything but long to work for the increment and assigned key strategies. Anything but long seems to produce a runtime cast class exception (that its trying to convert either int or short into a long). This is the case for both explicitly defined and hibernate assigned ids

Code:
Exception in thread "main" java.lang.ClassCastException
        at net.sf.hibernate.type.ShortType.set(ShortType.java:26)
        at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:46)
        at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:31)
        at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:377)
        at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:476)
        at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:454)
        at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:20)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2100)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2061)
        at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1566)
        at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1372)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1332)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1322)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1314)
        at testdb2.Main.main(Main.java:59)

OR
Code:
Sep 2, 2003 12:59:22 PM net.sf.hibernate.util.ReflectHelper$Setter set
SEVERE: IllegalArgumentException in class: testdb2.Employee, setter method of property: employeeId
Sep 2, 2003 12:59:22 PM net.sf.hibernate.util.ReflectHelper$Setter set
SEVERE: expected type: int, actual value: java.lang.Long
Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch
        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 net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:45)
        at net.sf.hibernate.persister.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:251)
        at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:674)
        at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605)
        at testdb2.Main.main(Main.java:69)
rethrown as net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling: argument type mis
match setter of testdb2.Employee.employeeId
        at net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:71)
        at net.sf.hibernate.persister.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:251)
        at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:674)
        at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605)
        at testdb2.Main.main(Main.java:69)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
        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 net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:45)


Thanks for the help!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 2:08 pm 
Newbie

Joined: Mon Sep 01, 2003 5:34 pm
Posts: 4
I forgot to say what the xml declarations were that were causing the problem:

Code:
<id type="int">
  <generator class="increment"/>
</id>

- OR -

Code:
<id  name="departmentID" column="DepartmentID" >
  <generator class="assigned"/>
</id>
where departmentID is of type int


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 6:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
In the case of your "assigned" mapping, as i said before, the same problem! You must specify a type attribute.

In the case of "increment", and i _think_ this is as per the documentation, the IncrementGenerator in 2.0.x only supports generation of long or Long. In 2.1 it supports ints and shorts also.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 10:02 am 
Newbie

Joined: Fri Oct 14, 2005 9:55 am
Posts: 5
Location: Bergen, Norway
gavin wrote:
The id name is optional only if you want no identitier property. I would STRONGLY recommend that you use an identifier property, however.


The exception is really quite self-explanatory: you did not specify an identifier type.


Obviously, if you don't specify an id property, you need to be explicit with the id type attribute.


I only use some simple VO objects to get some R/O results from a DB - and don't need any ID. How do I specify this? I'm using hibernate3 8with Spring 1.2.5)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.