-->
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.  [ 1 post ] 
Author Message
 Post subject: Not able to load Entity
PostPosted: Tue Sep 16, 2008 1:26 am 
Newbie

Joined: Wed Jul 23, 2008 1:59 am
Posts: 4
I have two tables(Database: Microsoft SQL Server)
1) Parent
2) Child


There is one-to-one relationship between them

Parent table have primary field ANC_ID(int)
Child table have field ANC_ID(int)



Parent class have following relation with Child

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ANC_ID")
private Child childString;

@Id
@Column(name = "ANC_ID")
private Integer annId;


Child declare relationship as follows

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ANC_ID")
private Parent ParentString;

@Id
@Column(name = "CONFIG_ID")
private String configId;




List<Parent> parent= session.createCriteria(Parent.class).list();

On Retrieving data from the entity i got the following exception

org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.String, got class java.lang.Integer

But when i change table structure as
Parent table have primary field ANC_ID(varchar(50))
Child table have field ANC_ID(varchar(50))

i got following
ERROR [10:43:16] - Invalid column name 'CONFIG_ID'.
org.hibernate.exception.SQLGrammarException: could not load an entity: [com.myprog.hibernate.per.entity.Child#1]

But column name is not invalid


Where m going not as required
is there something to keep in mind while using hibernate that primary keys must be Integer type (not String) and auto increment must be there

or Child tables primary key must be int


What is the correct scenario in which one can implement as required


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.