-->
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.  [ 5 posts ] 
Author Message
 Post subject: Java primitive type for id?
PostPosted: Wed May 12, 2004 3:44 am 
Newbie

Joined: Fri May 07, 2004 11:16 am
Posts: 14
Can I use a java primitive type for id in my persistent classes. ("int" for example) ?

If yes, the Session.load metho needs a Serializable object as id value, can I use the java.lang.Integer class even if my class memeber is a primitive "int"? As this: session.load(clazz, new Integer(id));

Other thing: I have a problem which may be linked with my previous question: at the beginning af my application, I got this exception:
net.sf.hibernate.MappingException: Error reading resource
...
Caused by: net.sf.hibernate.MappingException: invalid mapping
...
Caused by: org.xml.sax.SAXParseException: The content of element type "id" must match "(meta*,column*,generator


I have a very very simple mapping:
<hibernate-mapping>
<class name="test.Entity" table="Entities">
<id name="id" type="int" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" type="string"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 5:02 am 
Newbie

Joined: Fri May 07, 2004 11:16 am
Posts: 14
Please help :(
I don't find the problem for the exception :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 5:40 am 
Newbie

Joined: Fri May 07, 2004 11:16 am
Posts: 14
Concerning the SaxParser Exception: if i modify the example provided with hibernate (eg folder), adding addClass(Entity.class); i get no exception and the class is well mapped??? Why it fails in my own classes?
(I copied the hibernate.properties and the log4j.properties)


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 6:16 am 
Newbie

Joined: Fri May 07, 2004 11:16 am
Posts: 14
Ok i found the problem for the exception... In my project i used another version of xerces... so the old one was used instead of the one provided with hibernate libs...

Now let's talk about my first question "Can I use a java primitive type for id in my persistent classes. ("int" for example) ? " ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 7:47 am 
Beginner
Beginner

Joined: Fri Oct 17, 2003 4:11 am
Posts: 40
Concerning the id: as you can read in the ref guide (4.1.3) it's better to use a nullable object for identifiers (like java.lang.Long). I always use Long and it works good!

Gio


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