-->
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: mapping view USER_COL_COMMENTS ?
PostPosted: Wed Jun 18, 2008 5:19 am 
Newbie

Joined: Tue Jun 17, 2008 3:23 am
Posts: 5
Hi, I made a hibernate-mapping of a view USER_COL_COMMENTS, here is the code:
<hibernate-mapping>
<class name="com.model.Comments" table="USER_COL_COMMENTS">
<composite-id>
<key-property name="tableName"/>
<key-property name="columnName"/>
</composite-id>
<property name="tableName" column="TABLE_NAME" generated="never" not-null="true" />
<property name="columnName" column="COLUMN_NAME" generated="never" not-null="true" />
<property name="comments" column="COMMENTS" generated="never" not-null="true" />
</class>
</hibernate-mapping>


and then I deployed it, error appears:
2008-06-18 11:42:34,929 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <could not complete schema update>
org.hibernate.exception.SQLGrammarException: could not get table metadata: USER_COL_COMMENTS


any idea ?
thx in advance for any help
manos



Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html



Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 7:49 am 
Newbie

Joined: Wed Jun 11, 2008 6:36 am
Posts: 10
first of all look at the schema of your view

does it contain a column named "tableName" because in your mapping of the composite-id you have the following

<key-property name="tableName"/>
<key-property name="columnName"/>

and you don't specify a column attribute, which makes hibernate conisder it the same as the name property which is "tableName" and seems that it dosen't found it. the same thing is for the second line "columnName"


another thing that may arrise is that as i would suppose that the column in the table that has the value of the tableName is TABLE_NAME(i may be wrong) however in that case you would have the following

<composite-id>
<key-property name="tableName" column="TABLE_NAME"/>
<key-property name="columnName" column="COLUMN_NAME"/>
</composite-id>

which will introduce a new problem which is that you are mappiing the same column to two different members in the class. if you look down in your mapping you will find the other mapping.

<property name="tableName" column="TABLE_NAME" generated="never" not-null="true" />

which also maps the column TABLE_NAME so you must add two new properties update="false" insert="false"



try these modifications.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 10:18 am 
Newbie

Joined: Tue Jun 17, 2008 3:23 am
Posts: 5
thx for your help.
here is the description of the view:
VIEW USER_COL_COMMENTS
Name Null? Type
----------------------------------------- -------- ----------------------------
TABLE_NAME NOT NULL VARCHAR2(30)
COLUMN_NAME NOT NULL VARCHAR2(30)
COMMENTS VARCHAR2(4000)

the view is System Tables of oracle.
my problem is how to map this view. If i don't write <composite-id>, the mapping is not valid. any suggestion ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 11:51 am 
Newbie

Joined: Wed Jun 11, 2008 6:36 am
Posts: 10
ok do the following

first create a new class that represents the ID

public class Id Impliments Serializable{

private String tableName;
private String columnName;

public id(String tableName, String columnName){
this.tableName = tableName;
this.columnname = columnName;
}

// add setters and getters for tableName and columnName;

}



after this create the POJO that you need
public class userColComments{

private Id id;
private String tableName;
private String columnName;
private String comment;

public userColComments(){}

//add setters and getters for the fields


}




and then make the following mapping

<composite-id name="id" class="it.w4.model.hibernate.Id">
<key-property name="tableName" access="field" column="TABLE_NAME"/>
<key-property name="columnName" access="field" column="COLUMN_NAME"/>
</composite-id>


<property name="tableName" column="TABLE_NAME" insert="false" update="false"/>

<property name="columnName" column="COLUMN_NAME" insert="false" update="false"/>

<property name="comment" column="COMMENTS"/>


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.