-->
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.  [ 7 posts ] 
Author Message
 Post subject: many-to-one: MappingException: No persister for: java.lang.
PostPosted: Wed Oct 01, 2003 4:33 pm 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
Hi,

Parent and Child relationship, one Parent has many Children as described in Chapter 8 of the docs.

Parent has a <bag> of children:
Code:
...
        <bag name="children"
            inverse="true"
            lazy="true"
            cascade="all">

            <key column="parentId"/>
            <one-to-many class="test.Child"/>


Child has many-to-one property:

Code:
...
        <many-to-one name="parentId" not-null="true" unique="false"
            class="test.Parent"/>



When I run the code I get the net.sf.hibernate.MappingException: No persister for: java.lang.Integer

Any ideas? Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 5:22 pm 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
Additional info:

parentId and childId are PKs of Parent and Child respectively and are of type int

Version:
Hibernate 2.1 beta 3 (b)

Stacktrace:
net.sf.hibernate.MappingException: No persister for: java.lang.Integer
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:305)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2487)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2494)
at net.sf.hibernate.impl.SessionImpl.isUnsaved(SessionImpl.java:883)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:829)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:815)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:751)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:642)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1227)
at net.sf.hibernate.engine.Cascades$5.cascade(Cascades.java:105)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:280)
at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:373)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:296)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:331)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:773)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:642)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1227)
at com.ifintec.rc.entity.HibernateSecurityTest.testSecurity(HibernateSecurityTest.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 5:45 pm 
Beginner
Beginner

Joined: Thu Sep 25, 2003 5:22 pm
Posts: 29
Location: NC
I had this problem but can't remember how I resolved it. I think that I had been declaring my setters and getters for the primary keys as taking and returning a primitive int, and when I changed them to the class Integer, that it helped alleviate this problem. I seem to remember there being something else though...

Can you post your java classes? It might also be a problem with the way you set up your parent-child relationships with the getter and setter for the foreign key field in the parent.

-Kat


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 7:24 pm 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
Kat wrote:
Can you post your java classes? It might also be a problem with the way you set up your parent-child relationships with the getter and setter for the foreign key field in the parent.
-Kat


It breaks when HB tries to nullifyTransientReferences() for many-to-one relationship of the Child. I have no idea why.

Thanks

Code:
import java.util.List;

public class Parent {
private int parentId;
private String name;
private List children;

public int getParentId() { return parentId; }
public void setParentId(int parentId) { this.parentId = parentId; }

[...]
public List getChildren() { return children; }
[...]

// other getters and setters in the same manner
}

public class Child {
private int childId;
private String name;
private int parentId;

public int getParentId() { return parentId; }
public void setParentId(int parentId) { this.parentId = parentId; }

[...]
// other getters and setters in the same manner
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 4:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I had this problem but can't remember how I resolved it. I think that I had been declaring my setters and getters for the primary keys as taking and returning a primitive int, and when I changed them to the class Integer, that it helped alleviate this problem.



No, this would never be the problem. Hibernate does not distinguish between primitive and wrapper types.



The problem in -this- case is that you have mapped a property of type int as a many-to-one association! The property should be of type Parent.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 11:08 am 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
gavin wrote:
Quote:
The problem in -this- case is that you have mapped a property of type int as a many-to-one association! The property should be of type Parent.


The Child's parentId property was changed to be "parent" (as shown below) but that did not appear to resolve the issue. Now the error is "Fail to add null value in not null attribute parentid in Child"

Ironically, that was the reason I added many-to-one property to the Child in the first place; without it HB would try to insert '0' as the Child's parentId or, in other words, when new Parent and Child are created, the parentId is not properly set in the Child.

Any ideas? Thanks

Parent mapping:
Code:
...
        <bag name="children"
            inverse="true"
            lazy="true"
            cascade="all">

            <key column="parentId"/>
            <one-to-many class="test.Child"/>



Child mapping:
Code:
...
        <many-to-one name="parent" column="parentId" not-null="true" unique="false"
            class="test.Parent"/>


Child class:
Code:
public class Child {
private int childId;
private String name;
private Parent parent;

public Parent getParent() { return parent; }
public void setParent(Parent parentId) { this.parent = parent; }

[...]
// other getters and setters in the same manner
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 12:20 pm 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
oneway wrote:
The Child's parentId property was changed to be "parent" (as shown below) but that did not appear to resolve the issue. Now the error is "Fail to add null value in not null attribute parentid in Child"


Never mind. I forgot to set Child's parent after Child was created. It works. Thanks.


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