Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » generate entity classes from DB with TableGenerator
generate entity classes from DB with TableGenerator [message #657522] Thu, 03 March 2011 07:44 Go to next message
moritz du is currently offline moritz duFriend
Messages: 102
Registered: February 2010
Senior Member
my JPA-design approach is to design the data base first then let some tool generate JPA-code from it. at the moment i am using netbeans to generate entity classes.

to be flexible, portable and enable batch-writing (on mysql) i use "tableGenerator" for id-generation.

the problem is how to set up the data base schema to get "tableGenerator"-code generated from schema. is this possible with some jpa-code generator?

or how to get a setup where i don't have to touch generated code and have a tablegenerator?


(another relating question what are the deafult names if i use @GeneratedValue(strategy=GnerationType.Table) in conjunction with mysql?)

thx in advance
Re: generate entity classes from DB with TableGenerator [message #657636 is a reply to message #657522] Thu, 03 March 2011 14:28 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The default sequence table generated is,

CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR2(50) NOT NULL, SEQ_COUNT NUMBER(38) NULL, PRIMARY KEY (SEQ_NAME))

You also need to insert one row for each sequence name.

If you generate the DDL from the JPA model, it will do this for you.

Check if NetBeans allows any defaults to be configured when generating the JPA model, such as the Id generator.


James : Wiki : Book : Blog : Twitter
Re: generate entity classes from DB with TableGenerator [message #657646 is a reply to message #657522] Thu, 03 March 2011 15:05 Go to previous message
moritz du is currently offline moritz duFriend
Messages: 102
Registered: February 2010
Senior Member
"The default sequence table generated is,

CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR2(50) NOT NULL, SEQ_COUNT NUMBER(38) NULL, PRIMARY KEY (SEQ_NAME))"

thx for this

"If you generate the DDL from the JPA model, it will do this for you.

Check if NetBeans allows any defaults to be configured when generating the JPA model, such as the Id generator."

i generate the other way round - from database (model) to jpa (i am somewhat oldschool - designing first the data model erm based and then try to map it to objects via jpa-generators or with a minimum of handwork)

netbeans seem to only support "GenerationType.IDENTITY" - this is used if there is an auto increment primary key. if auto increment is disabled netbeans produces code without any "@generatedValue"

probably netbeans recognize a id-table if its named "SEQUENCE" ?

Or is there any db->jpa generator that supports generating @TableGenerator from a (given) id-table?
Previous Topic:[JPA-Newbie] -- JPA 2 for dynamic/custom entity types (database schemas)?
Next Topic:Foreign Key Constraint Issue Involving One-To-Many and Many-To-One Relationship in EcliplseLink2.1.
Goto Forum:
  


Current Time: Thu Oct 10 02:35:20 GMT 2024

Powered by FUDForum. Page generated in 0.03468 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top