File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes OneToOne relation gives problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "OneToOne relation gives problem " Watch "OneToOne relation gives problem " New topic
Author

OneToOne relation gives problem

deepan thiagu
Greenhorn

Joined: May 15, 2007
Posts: 18
This is my TBL_PRODUCTS table structure is

This is my TBL_CELLPHONE table structure is

This is my TBL_CELLPHONE table structure is

my entity beans are

TblProducts is my main table. I try to add OneToOne relation with other tables (TblTelevision and TblCellphone). I cant add more than one relation. If I add it gives incomplete deployment problem. If I remove any one of the OneToOne relation from TblProducts its works fine.
Is there any mistake in my code
Please help me

By
Thiagu.m
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
First of all, it is never a good idea to use BigDecimal, or any floating point type, as a PK. Turns out that 1.0 may not be equal to 1.0 when rounding happens.

For your OneToOne relationships in your CellPhone and Television entity classes you should probably use the PrimaryKeyJoinColumn annotation to indicate that you are using the PK as the join column. For example, your cell phone class would look like:

@Entity
@Table(name="TBL_CELLPHONE")
public class TblCellphone implements Serializable {
@Id
@Column(name="PRODUCT_ID")
Integer productId;

String bluetooth;
String camera;

@OneToOne
@PrimaryKeyJoinColumn
TblProducts tblProducts;
}


-Mike
Pro JPA 2: Mastering the Java Persistence API
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Which app server are you using?
What error are you getting? (show us the output)


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Is a cellphone a type of product?
Is a television a type of product?

Are you sure you don't want an inheritance relationship?
EJB will map a table-per-class for you and maintain the 1-1 relationship of table entries.

In which case you want:

[ January 21, 2008: Message edited by: Bill Shirley ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: OneToOne relation gives problem
 
Similar Threads
Beginner needs help with updating PK
hibernate: retrieving only part of child collection
more than one, OneToOne relation gives problem
Edit primary key, if it's a foreign key
OneToOne composite key