-->
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.  [ 3 posts ] 
Author Message
 Post subject: hibernate hbm2java
PostPosted: Mon Sep 28, 2009 3:23 am 
Newbie

Joined: Mon Sep 28, 2009 2:57 am
Posts: 3
Hi,
I'm wondering if I have wrong table setup, and I wanted to understand if what I'm generating is correct.
I'm using MySQL and I have two tables for example:

Code:
create table t1 (
t1id integer not null auto_increment primary key,
first varchar(20) not null,
last varchar(20) not null,
age integer null
) type=innodb;

create table t2 (
t1id integer not null,
index ( t1id ),
phone_number varchar(20) null,
phone_type varchar(20) null,
  CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1id`) REFERENCES `t1` (`t1id`)
  ON DELETE NO ACTION ON UPDATE NO ACTION
) type=innodb;


Basically the relationship between the two one to many. you can have multiple t2 records to a single t1 record. When I generate the entities, hbm2java is creating three files:
Code:
t1.java
t2.java
t2Id.java


In generating the entities I see the following:

Code:
[hibernate] Sep 28, 2009 3:05:37 AM org.hibernate.cfg.reveng.JDBCReader processPrimaryKey
[hibernate] WARNING: The JDBC driver didn't report any primary key columns in t2. Asking rev.eng. strategy
[hibernate] Sep 28, 2009 3:05:37 AM org.hibernate.cfg.reveng.JDBCReader processPrimaryKey
[hibernate] WARNING: Rev.eng. strategy did not report any primary key columns for t2


The t2Id.java file is throwing me off. Does this mean I have a created my tables in the wrong way? It seems like the table relationship is ok, where I have defined the key in the second table to be a foreign key which is the primary key in the first.

Is there away I can eliminate the Id file?

Thank you,
Christopher


Top
 Profile  
 
 Post subject: Re: hibernate hbm2java
PostPosted: Tue Sep 29, 2009 5:49 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
Create a PK in t2 table and try.

Whenever you are posting forum then please post your code aswell... it would be helpful to resolve.

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject: Re: hibernate hbm2java
PostPosted: Sat Oct 03, 2009 3:29 pm 
Newbie

Joined: Mon Sep 28, 2009 2:57 am
Posts: 3
Thanks, I figgured this out as well. The primary key isn't really needed
For this model.

Do all reversed engineered tables need a primary key?

This is a simple one-to-many table relationship.
You mentioned to show code, what other code is there? The table
Sql was provided, and everything else is automated.

Threre is no other code to post.

Thanks for the help.
-Christopher


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