-->
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.  [ 6 posts ] 
Author Message
 Post subject: Work with a database View
PostPosted: Tue Jun 12, 2007 9:42 am 
Newbie

Joined: Fri May 25, 2007 4:03 am
Posts: 15
Hi!
Someone know how I can work with hibernate and a view?
can I handle i view like i table?
what I have to set at the mapping file at primary key because the view hasnt someone?

code snippets:
mapping file:
Code:
<?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 package="at.pcd.wam.technologie.persistence.model">
  <class name="at.pcd.wam.technologie.persistence.model.LocationPortalModel" table="V_STANDORT_PORTAL" >
   <!-- primary key -->
     <id name="id" type="string" column="E_30021_DBK">
     <generator class="increment"></generator>
     </id>     

   <property name="dbk" type="string" column="E_30019_DBK"></property>
   <property name="district" type="string" column="BEZIRK"></property>
   <property name="boroughNumber" type="integer" column="GEMEINDE_NR"></property>

  </class>
</hibernate-mapping>

--> table equals view name?
--> what I have to do with the primary key?

best regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 10:01 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
>> can I handle i view like i table?
Yes.
Underlying database object ( table / view / synonym ) is transparent to Hibernate.

>>what I have to set at the mapping file at primary key because the view hasnt someone?
It is mandatory for all hibernate Entities to have an ID.
This is true in all cases. ( view / table / ... )
Further,
Any table ( or view ) should have at least one key to be in 1NF ( First Normal Form )
In extreme case, this could be a composite key with all columns.


------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 10:50 am 
Newbie

Joined: Fri May 25, 2007 4:03 am
Posts: 15
thx, now i tried this but following exception occurred:

Code:
org.hibernate.exception.GenericJDBCException: could not execute query


Code:
java.sql.SQLException: Konvertierung zu interner Darstellung nicht erfolgreich

means -->
Code:
java.sql.SQLException: Fail to convert to internal representation



my view contains varchar columns and number columns:
varchar = string
number = double ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 11:59 am 
Newbie

Joined: Fri May 25, 2007 4:03 am
Posts: 15
query, in sb:
Code:
SELECT * FROM V_STANDORT_PORTAL WHERE E_30019_DBK =  '301920000630141504440001' AND V_STANDORT_PORTAL.ANZAHL > 0


following get a response of "Ljava.lang.Object" but with them i cant work (casts didnt work):
Code:
values = (ArrayList<LocationPortalModel>) session.createSQLQuery(sb.toString()).list();   


if i run following it never comes to an end (no exception no end):
Code:
values = (ArrayList<LocationPortalModel>) session.createQuery(sb.toString()).list();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 1:18 pm 
Newbie

Joined: Tue Jun 12, 2007 12:36 pm
Posts: 6
I'm not sure about your casting problem, but for the .createQuery() method, it is expecting an HQL statement, not SQL.

The HQL equivalent would be:
Code:
from LocationPortalModel where dbk = '301920000630141504440001' and [i]anzahl[/i] > 0


I left "anzahl" in there as a place holder because it should be the property on your persistence object, but I don't see that column mapped to anything in the mapping you posted...[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 1:50 am 
Newbie

Joined: Fri May 25, 2007 4:03 am
Posts: 15
Well I also tried the following statement:
Code:
session.createQuery("from LocationPortalModel")list();


And this also didnt worked - hibernate will never come to an end - i always must break the calling.


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