-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Insert entity using Hibernate JPA
PostPosted: Thu Mar 09, 2017 2:46 pm 
Newbie

Joined: Thu Mar 09, 2017 2:02 pm
Posts: 1
Hi,
I am newbie at Hibernate. I need to insert entity Posts. But this entity has one to many with other tables. Here is described the structure of Database. https://code.tutsplus.com/tutorials/understanding-and-working-with-data-in-wordpress--cms-20567

Here is my entity
Code:
package .api.model;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@Table(name = "wp_posts")
@XmlRootElement
public class PlaceInsert {
   
   @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Basic(optional = false)
    @Column(name = "ID", unique = true, nullable = false)
   private Long placeid;
   
   @Basic(optional = false)
    @Column(name = "post_title", unique = true, nullable = false)
   private String placeTitle;
   
   @Basic(optional = false)
    @Column(name = "post_name", unique = true, nullable = false)
   private String placeName;
   
   [b]@OneToMany(fetch = FetchType.LAZY, mappedBy = "post_meta")
   private String placeAddress;
   private double locationX;
   private double locationY;
   private int city;
   private String phone;
   private String webUrl;
   private String fbUrl;
    private String googleUrl;
    private String twitterUrl;[/b]
   
   
   [b] private int category;
    private String post_excerpt;[/b]




The parts which I selected with bold are related with one-to-many relationship from other tables. Which annotations i must use? Or I must create 3 different entities?


Top
 Profile  
 
 Post subject: Re: Insert entity using Hibernate JPA
PostPosted: Sun Mar 12, 2017 2:46 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The @OneToMany must be set to a collection of child entities. So, yes, you need to map the child entities as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


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

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.