Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Hibernate

  Asked By: Qadriyah    Date: Sep 22    Category: Java    Views: 476
  

I have some questions regarding to Hibernate


first question :

there ara three classes as follow :
1- UserCity class
2- User class
3- Personal class
Personal class and user class have many-to-one relation by means of
primary key.
We use this relation for inner joining of User class and Personal
class.
now we need to define field C in id tag.
for outer joining of UseCity class and user class.
for this reason filed C should be deleted from property tag and as a
result it makes som problems in relation betwen user class and
personal class.
what is solution?can we define a variable as both id and property?
how we can inner join User class and Personal class and at the same
time to outer join User class and UserCity class?

second question:

We have two classes.one of them is User class and otherone is
UserCity class.
We have mapped the Usercity class to User class from inside of XML
file of User class in the form of one-to-many.
this mapping will do through usercity List in User class.can we query
directly through HQL in the form of joining from both of them
(User class and usercity class) instead of searching in usercity list
through java codes?

Thanks for your kind assistance.

best regards.

My XML files:


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"hibernate.sourceforge.net/...rnate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="untitled4.Personal" table="tbl_Personal">

<id name="Id" type="int" column="id">
<generator class="increment"/>
</id>

<property name="C" column="C" type="int"/>
<property name="Name" column="Name" type="string"/>
<property name="LastName" column="LastName" type="string"/>
<property name="AddOstan_C1" column="AddOstan_C1" type="int"/>
<property name="AddCity_C2" column="AddCity_C2" type="int"/>
<property name="AddNo" column="AddNo" type="string"/>
<property name="AddStr" column="AddStr" type="string"/>
<property name="AddAll" column="AddAll" type="string"/>
<property name="PhoneNo" column="PhoneNo" type="string"/>
<property name="EMail" column="EMail" type="string"/>
<property name="description" column="description"
type="string"/>
<property name="AddAve" column="AddAve" type="string"/>

<one-to-one name="users"
class="untitled4.User"
outer-join="false"
foreign-key="tbl_Personal_C"/>


</class>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"hibernate.sourceforge.net/...rnate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="untitled4.UserCity" table="tbl_User_City">

<id name="Id" type="int" column="id">
<generator class="increment"/>
</id>



<property name="tbl_Region_C1" column="tbl_Region_C1"
type="int"/>
<property name="tbl_Region_C2" column="tbl_Region_C2"
type="int"/>


<many-to-one name="user" column="tbl_User_C"
class="untitled4.User" property-ref="C" foreign-key="tbl_User_C"/>






</class>


</hibernate-mapping>




<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"hibernate.sourceforge.net/...rnate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="untitled4.User" table="tbl_User">

<id name="Id" type="int" column="id">
<generator class="increment"/>
</id>

<property name="C" column="C" type="int"/>
<property name="UserName" column="UserName" type="string"/>
<property name="Pass" column="Pass" type="string"/>
<property name="UserAccess" column="UserAccess" type="int"/>
<property name="Role" column="Role" type="int"/>
<property name="AccessLevel" column="AccessLevel" type="int"/>
<property name="UserDescription" column="UserDescription"
type="string"/>

<many-to-one name="Personals" column="tbl_Personal_C"
class="untitled4.Personal" property-ref="C" foreign-
key="tbl_Personal_C" />

<bag name="usercity" inverse="true" cascade="all,delete-
orphan">
<key column="C"/>
<one-to-many class="untitled4.UserCity"/>
</bag>

</class>


</hibernate-mapping>

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Hibernate Or get search suggestion and latest updates.




Tagged: