You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by "Howard W. Smith, Jr." <sm...@gmail.com> on 2014/01/14 13:30:35 UTC

Re: JPA @OneTOMany VS. @OneTOMany with @ManyToOne ??

Mauro,

Instead of explaining the difference, I will just share my example/code
that may be similar to code you shared. My code works as expected.

First, the CUSTOMER entity,

@Entity
@Table(name = "CUSTOMER")
public class Customer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "CUSTOMER_ID")
    private Integer customerId;

    @OneToMany(mappedBy = "customerId")
    private Collection<Orders> orders;

...

}


and the ORDERS entity,


@Entity
@Table(name = "ORDERS")
public class Orders implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "ORDER_ID")
    private Integer orderId;


    @JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "CUSTOMER_ID")
    @ManyToOne
    private Customer customerId;


...

}

On Tue, Jan 14, 2014 at 5:53 AM, mauro2java2011 <ma...@gmail.com>wrote:

> hi all .
> I have not understand the difference from the use relationship @OneToMany
> standalone or @OneToMany with @ManyToOne.
>
> A example:
> i have 2 entity:
> Customer
> Order
>
> ! Customer can have many order .
>
> So into the entity Customer i have :
>
> @Entyty
> Customer
>
> @Id
> Integer id;
> String nameCustomer;
>
> @OneTOMany
> Set ordersCustomer ;
>
> // other think
> .............................................................
> @Entity
> Order
>
> @Id
> Integer id;
>
> String description_product:
> Double amount-order;
>
> .................................................
>
> it is not sufficient for use it????
>
> what it is the difference to use also :
> -------------------------------------------------------
>
> @Entyty
> Customer
>
> @Id
> Integer id;
> String nameclient;
>
> @OneTOMany (mappedby=customer)
> Set ordersCustomert ;
>
> // other think
>
> -------------------------
> @Entity
> Order
>
> @Id
> Integer id;
>
> String descriptionofproduct:
> Double amount-order;
>
> Customer customer;
>
> -------------------------------------
>
> Please i ask difference conceptual s and difference int othe geneeration
> tables into DB .
> Takl you for your attention .
> Mauro
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/JPA-OneTOMany-VS-OneTOMany-with-ManyToOne-tp4667161.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: JPA @OneTOMany VS. @OneTOMany with @ManyToOne ??

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
Click URL and read/study the search results:

http://lmgtfy.com/?q=stackoverflow+java+onetomany+manytoone+jpa




On Tue, Jan 14, 2014 at 8:36 AM, mauro2java2011 <ma...@gmail.com>wrote:

> But if into entiry Order i not put the field Customer customerId ?
>
> Or if into entity Customet i not put the field Collection<Order> and  just
> into tge Entity Order i pyt a field Customet
> Custoner?
> Into tgw entytt Custimer not reference at entyty Order .
>
> I can get the ordervwith a select qyery s
>
> Finallt tge sak it is:
>
> When i use @OneToMany or @ManyToOne i have to use both or it is possible
> use
> only one of 2 annotation?
> Mauro
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/JPA-OneTOMany-VS-OneTOMany-with-ManyToOne-tp4667161p4667165.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: JPA @OneTOMany VS. @OneTOMany with @ManyToOne ??

Posted by mauro2java2011 <ma...@gmail.com>.
But if into entiry Order i not put the field Customer customerId ? 

Or if into entity Customet i not put the field Collection<Order> and  just
into tge Entity Order i pyt a field Customet 
Custoner? 
Into tgw entytt Custimer not reference at entyty Order .

I can get the ordervwith a select qyery s

Finallt tge sak it is: 

When i use @OneToMany or @ManyToOne i have to use both or it is possible use
only one of 2 annotation? 
Mauro




--
View this message in context: http://openejb.979440.n4.nabble.com/JPA-OneTOMany-VS-OneTOMany-with-ManyToOne-tp4667161p4667165.html
Sent from the OpenEJB User mailing list archive at Nabble.com.