-->
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.  [ 8 posts ] 
Author Message
 Post subject: One to many relationship
PostPosted: Sun May 06, 2007 10:53 pm 
Newbie

Joined: Sun May 06, 2007 10:40 pm
Posts: 6
I hav three table, a role table, an action table and a composition permission table which contain roleId and actionId.

The code for RolePos.hbm.xml is
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="system.RolePos" table="role">
<id name="roleId" type="int" column="roleId" unsaved-value="0">
<generator class="increment"/>
</id>

<property name="roleName">
<column name="roleName"/>
</property>

<set name="properties" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="roleId" />
<one-to-many class="system.PermissionPos" />
</set>

</class>

</hibernate-mapping>

The code for ActionPos.hbm.xml is
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="system.ActionPos" table="action">
<id name="actionId" type="int" column="actionId" unsaved-value="0">
<generator class="increment"/>
</id>

<property name="actionName">
<column name="actionName"/>
</property>

<set name="properties" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="actionId" />
<one-to-many class="system.PermissionPos" />
</set>
</class>

</hibernate-mapping>

The code for PermissionPos.hbm.xml is
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="system.PermissionPos" table="permission">
<id name="roleId" type="int" column="roleId" unsaved-value="0">
<generator class="assigned"/>
</id>

<id name="actionId" type="int" column="actionId" unsaved-value="0">
<generator class="assigned"/>
</id>

<many-to-one name="roleId" class="system.RolePos" column="roleId"/>

<many-to-one name="actionId" class="system.ActionPos" column="actionId"/>
</class>

</hibernate-mapping>

After run the program, it shows Could not parse mapping document from resource PermissionPos.hbm.xml and Could not parse mapping document from resource PermissionPos.hbm.xml. Can anybody help me? Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 12:06 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi arjensen,

Why you have two ID in one HBM.From where you have read it.

<id name="roleId" type="int" column="roleId" unsaved-value="0">
<generator class="assigned"/>
</id>

<id name="actionId" type="int" column="actionId" unsaved-value="0">
<generator class="assigned"/>
</id>


To avoid these type of problem use XML Editor ,XML Buddy plugin ,Exadel plugin

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 12:24 am 
Newbie

Joined: Sun May 06, 2007 10:40 pm
Posts: 6
Hi Dharmendra,

So what should to edit for the composition xml? Should i change to

<property name="roleId" type="int">
<column="roleId" unsaved-value="0"/>
</property>

<property name="actionId" type="int">
<column="actionId" unsaved-value="0"/>
</property>

<many-to-one name="roleId" class="system.RolePos" column="roleId"/>

<many-to-one name="actionId" class="system.ActionPos" column="actionId"/>

I new for hibernate, so not very familiar for it. Thanks for ur help. ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 1:26 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Try to see composite tag for hibernate

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 2:04 am 
Newbie

Joined: Sun May 06, 2007 10:40 pm
Posts: 6
Hi,

I had look through the reference guide, but it stills could not parse mapping document. In permission(composite xml), i change to
<composite-id class="system.PermissionPos" mapped="true">
<key-many-to-one name="roleId" class="system.PermissionPos" column="roleId"/>
<key-many-to-one name="actionId" class="system.PermissionPos" column="actionId"/>
</composite-id>

so for role xml and action xml does i have to add one-to-many column too?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 3:00 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi arjensen,

what is mapped="true" where it is written reference.




<composite-id
name="propertyName"
class="ClassName"
unsaved-value="any|none"
access="field|property|ClassName">

<key-property name="propertyName" type="typename" column="column_name"/>
<key-many-to-one name="propertyName class="ClassName" column="column_name"/>
......
</composite-id>

Let me know your Exp level .That would be great to me to know your understanding so that i could replay according to that

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 5:30 am 
Newbie

Joined: Sun May 06, 2007 10:40 pm
Posts: 6
I new to hibernate ;)

Now for rolePos mapping file
<class name="system.RolePos" table="role">

<id name="roleId" type="int" column="roleId" unsaved-value="0">
<generator class="increment"/>
</id>

<set name="permissionPos" lazy="true" inverse="true" >
<key>
<column name="roleId" />
</key>
<one-to-many class="system.PermissionPos"/>
</set>

<property name="roleName">
<column name="roleName"/>
</property>
</class>

actionPos mapping file
<class name="system.ActionPos" table="action">

<id name="actionId" type="int" column="actionId" unsaved-value="0">
<generator class="increment"/>
</id>

<set name="permissionPos" lazy="true" inverse="true" >
<key>
<column name="actionId" />
</key>
<one-to-many class="system.PermissionPos"/>
</set>

<property name="actionName">
<column name="actionName"/>
</property>
</class>

and permissionPos composite mapping file
<class name="system.PermissionPos" table="permission">
<composite-id>
<key-many-to-one name="roleId" class="system.RolePos" not-null="true">
<column name="roleId" />
</many-to-one>

<key-many-to-one name="actionId" class="system.ActionPos" not-null="true">
<column name="actionId" />
</many-to-one>
</composite-id>
</class>

But it still can't run. I really no idea for this..


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 7:16 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
See some more example in google .

_________________
Dharmendra Pandey


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