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: How to get object in Hibernate where primaryKey is char[11]?
PostPosted: Mon Aug 21, 2006 2:50 am 
Newbie

Joined: Mon Aug 21, 2006 2:03 am
Posts: 3
I have a table for eg: User_tab.
The primarykey is id having datatype of char[11].
I associated the table with Usertab.java and primarykey with String.
while i want to get the Object using Session.load(Usertab.class,id) i am not getting the result .
I tried in different ways but i am not getting the result.

How do i do This?
Using load in Hibernate.Session and find in Spring HhibernateTemplate i am not getting result. resulting null values no Exception arises.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 4:47 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
please provide more info regarding this . you are supposed to follow the posting rule/ format to others to understand things better .

ie, always provide
1) Persistent class info
2) Mappings
3) code between session.open() and session.close()

unless irrevelent to ur subject

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 4:47 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
please provide more info regarding this . you are supposed to follow the posting rule/ format for others to understand things better .

ie, always provide
1) Persistent class info
2) Mappings
3) code between session.open() and session.close()

unless irrevelent to ur subject

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 7:30 am 
Newbie

Joined: Mon Aug 21, 2006 2:03 am
Posts: 3
Hi sHeRiN ,

Persistent class i had :

public class Usertab {
private String id;
private String empMgrID;
private String emLIST;
private String empFRT;
private String empMID;

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
........................................
}

Mappings file :

<?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="com.entity.Usertab" table="User_tab">
<!-- A 32 hex character is our surrogate key. It's automatically generated by Hibernate with the UUID pattern. -->

<id name="id" unsaved-value="null" >
<column name="ID" not-null="true"/>
</id>

<property name="empMgrID">
<column name="MGR" not-null="true"/>
</property>

<property name="empNMLIST">
<column name="LST" not-null="true"/>
</property>

<property name="empNMFRT">
<column name="FRT" not-null="true"/>
</property>

</class>
</hibernate-mapping>


[b]code between session.open() and session.close() :

Transaction transaction=null;
Session session=null;
try{
session=this.getSession();
transaction=session.beginTransaction();

Usertab Usertab =(Usertab)session.load(Usertab.class,id);
String empId=Usertab .getId();
String empId=Usertab .getEmpMgrID();

transaction.commit();
}
catch(Exception e){
transaction.rollback();
throw new DataAccessException(e.getMessage(),e);
}finally{
if(session !=null){
session.close();
}
}


here i had the table :

DESC User_tab;

ID CHAR[11],
MGR VARCHAR2[20]
LST VARCHAR2[20]
FRT VARCHAR2[20]

i had the table view only i want to get the data from the table.
here i am getting null object no value is returning. regarding this please help me.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 7:49 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
how did u save the data anyway ?
and i couldnt find a primary key <generator> element in ur <id > mapping .
i wonder if u were able to create a session factory with a required elemnt missing !!!!!

refer
http://www.hibernate.org/hib_docs/reference/en/html_single/#mapping-declaration-id-generator

your id mapping should be something like this

Code:
<hibernate-mapping>
<class name="com.entity.Usertab" table="User_tab">
<!-- A 32 hex character is our surrogate key. It's automatically generated by Hibernate with the UUID pattern. -->

<id name="id" unsaved-value="null" >
      <column name="ID" not-null="true"/>
      <generator class="uuid.string"> </generator>
</id>



please provide the debug level stack trace when posting with code snippets .... :)

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 9:33 am 
Newbie

Joined: Mon Aug 21, 2006 2:03 am
Posts: 3
Hi,
here i am not getting any Exception regarding the Object retrival.
Here i want to get the Usertab Object from table. The Table User_tab had only View possiblity.
Using Hibernate how i can get the Object value from a view. i had read only possibility. please let me know is there any modifications to do in Usertab.hbm.xml file to get the data.

i had the Persistent class As:


public class Usertab {
private String id;
private String empMgrID;
private String emLIST;
private String empFRT;
private String empMID;

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
........................................
}


and i had the Mapping file Usertab.hbm.xml file As :


<?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="com.entity.Usertab" table="User_tab">
<!-- A 32 hex character is our surrogate key. It's automatically generated by Hibernate with the UUID pattern. -->

<id name="id" unsaved-value="null" >
<column name="ID" not-null="true"/>
</id>

<property name="empMgrID">
<column name="MGR" not-null="true"/>
</property>

<property name="empNMLIST">
<column name="LST" not-null="true"/>
</property>

<property name="empNMFRT">
<column name="FRT" not-null="true"/>
</property>

</class>
</hibernate-mapping>


and the EmployeeDao.java class As:

public class EmployeeDao extends HibernateDaoSupport{

public UserTab getUser(String empId) throws DataAccessException{

Transaction transaction=null;
Session session=null;
try{
session=this.getSession();
transaction=session.beginTransaction();

Usertab usertab =(Usertab)session.load(Usertab.class,id);
return usertab;
transaction.commit();
}
catch(Exception e){
transaction.rollback();
throw new DataAccessException(e.getMessage(),e);
}finally{
if(session !=null){
session.close();
}
}
}


and also the table As:
User_tab:
ID CHAR[11],
MGR VARCHAR2[20]
LST VARCHAR2[20]
FRT VARCHAR2[20]


please provide slution for this.
thanks,
subha.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 1:39 pm 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
just go thru my previous reply . ive mentioned a change in hbm file .
and if you want to query a view rather than a table , i hope i can give u an answer for that later. if u are in a hurry, hopefully you will get an answer for that from the forum itself , when you search back

_________________
sHeRiN
thanks for your ratings ...... :)


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.