-->
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.  [ 4 posts ] 
Author Message
 Post subject: Trying to map a MySQL view using hibernate
PostPosted: Sat Feb 14, 2009 3:11 pm 
Newbie

Joined: Sat Feb 14, 2009 3:02 pm
Posts: 1
Hi, having a problem mapping my MySQL view below using Hibernate 3. I am new to Hibernate (from today) but finding limited information on mapping views - this view doesn't have a unique key as such so wondering if that is the problem. Any help appreciated!

MySQL view:

CREATE OR REPLACE VIEW `get_dashlets` (`d_id`, `d_title`, `d_description`, `d_scope`,
`f_id`, `f_thumbnail`, `f_author`,
`c_id`)
AS
SELECT d.id, d.title, d.description, d.scope, f.id, f.thumbnail, f.author, c.id
FROM dashlets d,
features f,
feature_categories c
WHERE (d.feature_id = f.id) and (f.id = c.feature_id);

Mapping documents:

<?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="database.dataEntities.GetDashlets" table="get_dashlets" catalog="sambajam">
<id name="dID" type="java.lang.Integer">
<column name="dID" />
<generator class="identity" />
</id>
<property name="title" type="string">
<column name="d_title" length="128" />
</property>
<property name="description" type="string">
<column name="d_description" length="16777215" />
</property>
<property name="scope" type="string">
<column name="scope" length="9" />
</property>
<property name="thumbnail" type="string">
<column name="thumbnail" length="128" />
</property>
<property name="author" type="string">
<column name="author" length="128" />
</property>
</class>
</hibernate-mapping>

Java POJO Class:

public class GetDashlets implements java.io.Serializable {


private Integer dID;
private String title;
private String description;
private String scope;
private String thumbnail;
private String author;

public GetDashlets() {
}

public GetDashlets(int dID, String scope) {
this.dID = dID;
this.scope = scope;
}
public GetDashlets(int dID, String title, String description, String scope, String thumbnail, String author) {
this.dID = dID;
this.title = title;
this.description = description;
this.scope = scope;
this.thumbnail = thumbnail;
this.author = author;
}

public Integer getdID() {
return this.dID;
}

public void setdID(Integer dID) {
this.dID = dID;
}

public String getTitle() {
return this.title;
}

public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return this.description;
}

public void setDescription(String description) {
this.description = description;
}

public String getScope() {
return this.scope;
}

public void setScope(String scope) {
this.scope = scope;
}

public String getThumbnail() {
return this.thumbnail;
}

public void setThumbnail(String thumbnail) {
this.thumbnail = thumbnail;
}

public String getAuthor() {
return this.author;
}

public void setAuthor(String author) {
this.author = author;
}
}

<b>Runtime Error:</b>
could not execute query


Top
 Profile  
 
 Post subject: Same issue
PostPosted: Tue Feb 24, 2009 2:13 pm 
Newbie

Joined: Tue Feb 24, 2009 2:11 pm
Posts: 3
I'm having the same issue. Please help.


Top
 Profile  
 
 Post subject: Try this
PostPosted: Tue Feb 24, 2009 4:10 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
This is how we have done(see below.). But this was in one of our previous projects and the hibernate version is different.
The only thing that is different i guess is the NEWID() definition.

MYSQL View:-
CREATE VIEW customer_cost
AS
SELECT
NEWID() AS id,
.. column selections

Hibernate Mapping:-
<class
name="com.xx.CustomerCost"
table="customer_cost"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="none"
>

<id
name="id"
column="id"
type="java.lang.String"
unsaved-value="null"
>
<generator class="assigned">
</generator>
</id>
other property mappings..

Hope this helps!
-latha.


Top
 Profile  
 
 Post subject: Re: Trying to map a MySQL view using hibernate
PostPosted: Tue Feb 24, 2009 6:51 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
I think you can use generator class="assigned" instead of identity


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