-->
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.  [ 3 posts ] 
Author Message
 Post subject: Getting Null value while accessing the database view.
PostPosted: Fri Apr 29, 2011 5:49 am 
Newbie

Joined: Fri Apr 29, 2011 5:30 am
Posts: 1
Hi all,
Am new to hibernate environment.I need to access the data from database view, while trying to fetch the data from database view, am getting the null value.

Also I execute the hibernate query in database separately and its work for me.

Does anyone help me, how to access the database view data?

Details :
1) hibernate 2.1
2) database 10G.

HBM file :

<hibernate-mapping>
<class name="com.reports.dataaccess.dao.domain.CapabilityBuildingView" table="CAPABILITY_BUILDING_VIEW">
<composite-id name="id" class="com.reports.dataaccess.dao.domain.CapabilityBuildingViewId">
<key-property name="portfolio" type="string">
<column name="PORTFOLIO" length="400" />
</key-property>
<key-property name="skill" type="string">
<column name="SKILL" length="500" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>


DAO :

session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
query = session.createQuery("from CapabilityBuildingView");

temp = (ArrayList<CapabilityBuildingView>) query.list();

for (CapabilityBuildingView master : temp) {
if (master != null){
master.getId().getByWhen();
master.getId().getCreatedBy();
master.getId().getCreatedDate();
master.getId().getCriticality();
master.getId().getCurrentCapabilityCount();
master.getId().getExcelupload();
master.getId().getFutureNeed();
master.getId().getLastUpdatedBy();
master.getId().getLastUpdatedDate();
master.getId().getPortfolio();
master.getId().getRemarks();
master.getId().getSkill();
master.getId().getSkillLevel();
}
}

cgf.xml :

<mapping resource="com/reports/dataaccess/dao/domain/CapabilityBuildingView.hbm.xml" />


Top
 Profile  
 
 Post subject: Re: Getting Null value while accessing the database view.
PostPosted: Sun May 01, 2011 3:29 am 
Newbie

Joined: Sun May 01, 2011 3:17 am
Posts: 2
Hi mnkumar,

This problem is may be due to the fact that your view may contain null values in any of the columns specified in COMPOSITE-ID section of the configuration.
Hibernate is fetching the null records which contain null values in the composite primary key,

So two solutions,

1) Change your hbm.xml and class files to make sure that the columns specified in the composite-id will always have not-null values
or
2) Create a primary key for your view. (If you are using any tools to generate the hbm files, try running the tool after creating the primary key on the view)

you can check http://psoug.org/reference/views.html for creating a primary key on the view.

Hope this helps.

_________________
Thanks,
Yuvana

We Always Get What We Deserve Nothing More Nothing Less


Top
 Profile  
 
 Post subject: Re: Getting Null value while accessing the database view.
PostPosted: Sun May 01, 2011 3:31 am 
Newbie

Joined: Sun May 01, 2011 3:17 am
Posts: 2
Similar Problem discussed here.
http://forum.springsource.org/showthread.php?p=358513

_________________
Thanks,
Yuvana

We Always Get What We Deserve Nothing More Nothing Less


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