-->
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.  [ 1 post ] 
Author Message
 Post subject: many-to-one relation logic
PostPosted: Wed Sep 08, 2004 12:55 pm 
Newbie

Joined: Wed Sep 08, 2004 12:01 pm
Posts: 1
Location: Paris, France
Hi all,

I try to use hibernate in a project and i just get into trouble.
To be simple, i've got 2 type of Java Object: Network and Line

Here is their java code (generated by Castor from XSD document):

public class PtNetwork
{
private java.lang.String _objectId; // Id
private java.lang.String _name;
.... whith all the getter and setter
}

public class Line
{
private java.lang.String _objectId;
private java.lang.String _name;
private java.lang.String _number;
.... whith all the getter and setter

private java.lang.String _ptNetworkIdShortcut;

public void setPtNetworkIdShortcut(java.lang.String ptNetworkIdShortcut)
{
this._ptNetworkIdShortcut = ptNetworkIdShortcut;
}

}


As you can see a Line know her network, or to be exact, a line knows the id of her network. That's where the problem begin.

Mapping documents:
My mapping is like this:

#for the Network
<hibernate-mapping>
<class
name="com.chouette.PtNetwork"
table="PtNetwork"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="objectId"
column="objectId"
type="java.lang.String"
>
<generator class="assigned">
</generator>
</id>


<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="name"
/>

</class>

</hibernate-mapping>

#for the Line
<hibernate-mapping>
<class
name="com.chouette.Line"
table="Line"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="objectId"
column="objectId"
type="java.lang.String"
>
<generator class="assigned">
</generator>
</id>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="name"
/>
<property
name="number"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="number"
/>
<many-to-one
name="ptNetworkIdShortcut"
class="com.chouette.PtNetwork"
cascade="none"
outer-join="auto"
column="ptNetworkIdShortcut"
/>
</class>
</hibernate-mapping>



When i try to save my line like this:

#create a network
PtNetworkn= new PtNetwork();
n.setObjectId("Network1");

#create a line
Line l=new Line();
l.setName("Line1");

#affect network id to the line
l.setPtNetworkIdShortcut(n.getObjectId());

#save the network
s.save(pn);

#save the line
s.save(l)

I,ve got this exception :
Exception in thread "main" net.sf.hibernate.MappingException: No persister for: java.lang.String
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2686)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2693)
at net.sf.hibernate.impl.SessionImpl.isUnsaved(SessionImpl.java:1090)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:1036)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:1022)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:927)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:857)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:779)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at testtransaction.main(testtransaction.java:186)



what must be many-to-one mapping logics ?
I read somewhere that it is had be simplier if the network reference of my line was an object like this

class Line
{
....

private PtNetwork _ptNetworkShortcut;
public void setPtNetworkIdShortcut(PtNetwork ptNetwork)
{
this._ptNetworkShortcut = ptNetwork;
}


....
}


but my code is generated by castor from an XSD document i can't change.

Anyone knows the goog way to create this simple association is welcome.

Thanks

PS : I use hibernate2 (downloaded a month ago) with postgreSQL 734
PS2 : let me knows if my mail isn't clear...


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

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.