[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-11 Thread Wolfgang Knauf
Hi kkangsar,

1) the DiscriminatorColumn name defaults to "DTYPE", so you need to specify the 
name only if you don't like the default ;-).

2) I don't have a simple answer this question ;-). Performance should not be an 
issue, because both approaches add the columns to the database table of the 
entity, so there are no additional entities. The approach with the @OneToOne 
relation ship (suggested by itsme) would result in an additional table. 
The benefit of the inheritance approach is that you don't need to add 
properties (access to your embedded object) to the subclass. So it saves you 
some lines of code ;-).

Hope this helps

Wolfgang

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216895#4216895

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216895
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-11 Thread itsme
This is only a decision of the architecture of your object (and following up 
the database) model.

We use address only as tight as possible with the persons we track. So the 
address is not useful anymore when the person is gone. To avoid keeping orphans 
in the database we inlined address fields by using @Embeddable.

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216890#4216890

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216890
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-11 Thread kkangsar
My understanding of using inheritance SINGLE TABLE method is when the object is 
polymorphism, it means the single object can be describes multiple possible 
states. 

For example: Account object, we may have SavingAccount and CheckingAccount, 
SavingAccount and CheckingAccount share some common attribute and have their 
own specific attribute. For this kind of object, we may use inheritance SINGLE 
TABLE method.

But in my case, Address.class, will it the right way to use this method? Please 
advise. Thanks.

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216866#4216866

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216866
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-10 Thread kkangsar
Hi Wolfgang,

 Thanks for provided another solution.  But I have the following question.

 1. Do we need to specify the @@DiscriminatorColumn in the Address class, 
if yes, which column to specify?

 2. What is the advantage by using @Inheritance over @Embedded? and when to 
use each of the method.

   

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216649#4216649

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216649
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-10 Thread Wolfgang Knauf
Hi,

though you already solved the problem, here is another idea: you could also use 
Inheritance strategies.

Declare your Address entity this way:
@Entity
  | @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
  | public abstract class Adress implements Serializable 
  | {
  | 
Let Person and Customer inherit from them:
@Entity
  | @DiscriminatorValue(value="person")
  | public class Person extends Address
  | {

Best regards

Wolfgang

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216534#4216534

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216534
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-10 Thread kkangsar
I got it. many thanks.



View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216479#4216479

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216479
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-10 Thread itsme
For the first one (use of @Embaddable and @Embedded) Customer class must be 
changed to:

  | @Entity
  | public class Customer implements Serializable {
  | // ... your member fields
  | private Address address;
  | // ... your set-/get-Methods
  | @Embedded
  | public Address getAddress() {
  | return address;
  | }
  | // ... setter as well
  | }
  | 

For the second one (keeping @Embeddable and building a wrapper):

  | @Entity
  | public class AddressWrapper implements Serializable {
  | 
  | @Id
  | private String id;
  | 
  | @Embedded
  | private Address address;
  | 
  | // getter and setter
  | }
  | 
In this case your Customer class must be changed like

  | @Entity
  | public class Customer implements Serializable {
  | // ... your member fields
  | private AddressWrapper address;
  | // ... your set-/get-Methods
  | @OneToOne
  | public AddressWrapper getAddress() {
  | return address;
  | }
  | // ... setter as well
  | }
  | 
For the last one you must change the annotation of Address to @Entity and 
change your Customer class like the above (without Wrapper).

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216472#4216472

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216472
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-10 Thread kkangsar
This is what i did

@Embeddable
public class Address implements Serializable{
private static final long serialVersionUID = 1L;
private String addr1;
private String addr2;
private String addr3;

@Column(name="ADDR1", length=30)
public String getAddr1() {
return addr1;
}
public void setAddr1(String addr1) {
this.addr1 = addr1;
}
@Column(name="ADDR2", length=30)
public String getAddr2() {
return addr2;
}
public void setAddr2(String addr2) {
this.addr2 = addr2;
}
@Column(name="ADDR3", length=30)
public String getAddr3() {
return addr3;
}
public void setAddr3(String addr3) {
this.addr3 = addr3;
}
}

@Entity
public class Customer implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private String Id;
private String custName;

@Id
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
}

I dont know how to embed the address into customer.class. Can you please give 
some help. Thanks


View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216469#4216469

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216469
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-10 Thread kkangsar
"If you want to reuse your address entity, so there will be a address table, 
you can create a simple wrapper for your address with nothing more than an 
identifier and an embedded field address or your address must be a full entity 
and not an embeddable."

Would you mind to provide me the sample code for the above? thanks in advanced.

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216467#4216467

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216467
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-10 Thread itsme
Yes. This is - especially for addresses - the common case, so there is no need 
to travers a relationship between tables.

If you want to reuse your address entity, so there will be a address table, you 
can create a simple wrapper for your address with nothing more than an 
identifier and an embedded field address or your address must be a full entity 
and not an embeddable.

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216462#4216462

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216462
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-10 Thread kkangsar
Do you mean my customer and vendor table will contain all the address column?

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216460#4216460

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216460
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: @embedable annotation

2009-03-10 Thread itsme
Per default hibernate creates your tables with all the fields of address as 
columns in that tables. So address is only a subset of columns of the table 
vendor or customer.

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216454#4216454

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216454
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user