-->
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: Plz Help -- No persister for: java.lang.Long
PostPosted: Mon Mar 22, 2004 4:44 am 
Newbie

Joined: Mon Mar 22, 2004 4:26 am
Posts: 3
Hello all,

i am trying to implement a relation of the following kind. A contracted product object references a product (id) through its id (product_ref_id). So i have defined two objects:
- Product:
with id (as primary key), code, etc...
- ContractedProduct:
with id, code, product_ref_id(foreign key), etc...

Following is the hbm file for ContractedProduct:
<hibernate-mapping package="com.xxx.bean">
<class name="ContractedProductBean" table="TEST_contracted_product">
<id name="id" type="long" unsaved-value="null">
<column not-null="false" name="ID"/>
<generator class="native"/>
</id>
<many-to-one class="ProductBean" name="product_ref_id" column="PRODUCT_REF_ID"/>
<property name="code" column="CODE" not-null="true" unique="true"/>
<property name="quantity" column="QUANTITY" not-null="false" unique="false"/>
</class>
</hibernate-mapping>


Following is the hbm file for product:
<hibernate-mapping package="com.xxx.bean">
<class name="ProductBean" table="TEST_product">
<id name="id" type="long" unsaved-value="null">
<column not-null="false" name="ID"/>
<generator class="native"/>
</id>
<property name="code" column="CODE" not-null="true" unique="true"/>
<property name="type" column="TYPE" not-null="true" unique="false"/>
<property name="category" column="CATEGORY" not-null="true" unique="false"/>
<property name="min_qty" column="MIN_QTY" not-null="false" unique="false"/>
<property name="label" column="LABEL" not-null="false" unique="false"/>
</class>
</hibernate-mapping>


when i try to save an object of type ContractedProduct:
ContractedProductBean contractedproduct=new contractedProductBean();
contractedproduct.setCode("mycode");
contractedproduct.setProduct_ref_id("an_existing_product_id");

when i save the object in the session (curSession.save(contractedproduct);), i got the following error

thanks a lot for your ideas!!

jbg


net.sf.hibernate.MappingException: No persister for: java.lang.Long
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2656)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2663)
at net.sf.hibernate.impl.SessionImpl.isUnsaved(SessionImpl.java:1064)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:1010)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:996)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:901)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:839)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:761)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:720)
at com.xxx.generator.DBLoader.loadContractedProducts(DBLoader.java:443)
at com.xxx.generator.DBLoader.loadContracts(DBLoader.java:410)
at com.xxx.generator.DBLoader.loadMembers(DBLoader.java:341)
at com.xxx.generator.DBLoader.loadLevels(DBLoader.java:304)
at com.xxx.generator.DBLoader.loadLevels(DBLoader.java:301)
at com.xxx.generator.DBLoader.loadCustomerData(DBLoader.java:98)
at com.xxx.generator.GenDB.populateDB(GenDB.java:87)
at com.xxx.generator.GenDB.main(GenDB.java:45)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 5:10 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
try without typing your id in your mapping file and don't forget that long (cannot be null) is not the same as Long (can be null).

<id name="id" unsaved-value="null">
<column not-null="false" name="ID"/>
<generator class="native"/>
</id>


Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 10:49 am 
Newbie

Joined: Mon Mar 22, 2004 4:26 am
Posts: 3
delpouve wrote:
try without typing your id in your mapping file and don't forget that long (cannot be null) is not the same as Long (can be null).

<id name="id" unsaved-value="null">
<column not-null="false" name="ID"/>
<generator class="native"/>
</id>


Anthony


I have tried this but without any success!!! :-(((
I should be making a trivial mistake as i just want to reference (with my foreign key) a collection of values from a class. (For instance, in a contact table, a country code value which would be referenced from a country table...

Does anybody have any sample like this? plz help me !

thanks a lot! for your time.

jbg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 11:39 am 
Newbie

Joined: Wed Mar 24, 2004 11:13 am
Posts: 15
Location: Norcross, GA
Is the product_ref_id of type long?
It should be of type ProductBean.

So your ContractedProduct class should be like
id - long or whatever the datatype
code - ditto
product_ref_id - ProductBean

Let me know if that doesnt work.
Madhu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 3:20 pm 
Beginner
Beginner

Joined: Wed Mar 17, 2004 4:13 pm
Posts: 21
Location: San Diego, CA
What's your SQL type?

The Hibernate Type.LongType api doc says it's for converting SQL BIGINT to a java Long.

Maybe you should try specifiying the type "integer"...at least to see what happens.

Chrisjan


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.