NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Entity Classes from Database

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users
View previous topic :: View next topic  
Author Message
MarkInLasVegas



Joined: 14 Dec 2009
Posts: 1

PostPosted: Mon Dec 14, 2009 8:29 am    Post subject: Entity Classes from Database Reply with quote

I am trying to create a one to many relationship from tables in a MySQL database.


Child table.

Note: "mech" is short for mechanism.

order_contact_mech
(
ORDER_ID VARCHAR(20) not null primary key,
CONTACT_MECH_PURPOSE_TYPE_ID VARCHAR(20) not null primary key,
CONTACT_MECH_ID VARCHAR(20) not null primary key,
.
.
.

)

-----------------------------------------------------------------------------------

When I select Entity Classes from Database...
I get two classes:

OrderContactMech.java
and OrderContactMechPK.java

How do I Join another table (order_header on Order_Id ) with OrderContactMech when the key fields are in OrderContactMechPK?

------------------------------------------------------------------------------------

Parent table.

order_header
(
ORDER_ID VARCHAR(20) not null primary key,
ORDER_TYPE_ID VARCHAR(20),
.
.
.
)

------------------------------------------------------------------------------------

Why does Netbeans create a separate class with the primary keys (OrderContactMechPK)?

In OrderContactMech.java I have:

@EmbeddedId
protected OrderContactMechPK orderContactMechPK;

What does this mean?

I want to create a one to many relationship from order_header to
order_contact_mech

------------------------------------------------------------------------------------

The important part seems to be:
@EmbeddedId
protected OrderContactMechPK orderContactMechPK;

If you could explain the @EmbeddedId part that should be enough for now. (Don't get overly concerned about table names, upper and lower case letters and underscores.)

A link to an actual example would be best.

Unfortunately, I cannot change the original tables in any way.


Thank you very much.

PS. I am trying this:

@OneToMany(mappedBy = ???)
private Collection<OrderContactMech???> OrderContactMechCollection???;
Back to top
Ernie Rael
Posted via mailing list.





PostPosted: Mon Dec 14, 2009 11:49 am    Post subject: [platform-dev] Re: Entity Classes from Database Reply with quote

On 12/14/2009 12:30 AM, MarkInLasVegas wrote:
Quote:
Quote:
I am trying to create a one to many relationship from tables in a MySQL database.

[snip]
Looks like most of your issues are about JPA and has little to do with NetBeans. Any NetBeans related questions are more appropriate for address-removed ([email]address-removed[/email]), see http://netbeans.org/community/lists/top.html .

That said, http://en.wikibooks.org/wiki/Java_Persistence has some good examples. Additionally the JPA spec or the recently published http://www.apress.com/book/view/9781430219569 are good sources.

-ernie
Back to top
Antonio Vieiro
Posted via mailing list.





PostPosted: Mon Dec 14, 2009 9:38 pm    Post subject: [platform-dev] Re: Entity Classes from Database Reply with quote

There's a foreign key missing somewhere!

On 14/12/09 12:49, Ernie Rael wrote:
Quote:
On 12/14/2009 12:30 AM, MarkInLasVegas wrote:
Quote:
I am trying to create a one to many relationship from tables in a MySQL database.

[snip]

Looks like most of your issues are about JPA and has little to do with
NetBeans. Any NetBeans related questions are more appropriate for
*address-removed, *see *http://netbeans.org/community/lists/top.html* .

That said, http://en.wikibooks.org/wiki/Java_Persistence has some good
examples. Additionally the JPA spec or the recently published
http://www.apress.com/book/view/9781430219569 are good sources.

-ernie
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users All times are GMT
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo