NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
MarkInLasVegas
Joined: 14 Dec 2009 Posts: 1
|
Posted: Mon Dec 14, 2009 8:29 am Post subject: Entity Classes from Database |
|
|
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.
|
Posted: Mon Dec 14, 2009 11:49 am Post subject: [platform-dev] Re: Entity Classes from Database |
|
|
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.
|
Posted: Mon Dec 14, 2009 9:38 pm Post subject: [platform-dev] Re: Entity Classes from Database |
|
|
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 |
|
 |
|
|
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
|
|