| 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
 
 
 |  |