jpa-2.0

Hibernate unidirectional OneToMany delete violates constraint ( optional=false at parent side?)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 12:25:04
问题 I use Hibernate 3.6 and I have something like this: @Entity public class Parent { @OnyToMany( fetch = FetchType.LAZY, cascade = { ascadeType.ALL } ) @Cascade( { org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE ) @JoinColumn( name="Parent_ID" ) public List<Child> getChildren() { return children; } public void setChildren( List<Child> children ) { this.children = children; } private transient List<TitleMetadataCategory> children; ... } @Entity

How to map collection of each subclass from same hierarchy onto one owning class?

天涯浪子 提交于 2019-12-06 12:07:20
问题 Does anyone know how to map a collection of each subclass from the same hierarchy onto one owning class, using JPA 2.0 annotations, backed by Hibernate 4.0.0.Final? Bit convoluted, so here's an example. Hierarchy classes look like this: @Entity @Cacheable(true) @Table(name = "hierarcicals") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "class", discriminatorType = DiscriminatorType.STRING) public abstract class MySuperClass { ... @Entity @DiscriminatorValue(

JPA 2.0 CriteriaQuery on tables in @ManyToMany relationship

馋奶兔 提交于 2019-12-06 09:50:40
I have two entities in a @ManyToMany relationship. // Output has 4 other @ManyToOne relationships if that matters @Entity @Table public class Output { @Id public String address; @ManyToMany(targetEntity = Interval.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable(name = "output_has_interval", joinColumns = {@JoinColumn(name = "output_address", referencedColumnName = "address")}, inverseJoinColumns = {@JoinColumn(name = "interval_start", referencedColumnName = "start"), @JoinColumn(name = "interval_end", referencedColumnName = "end")}) Collection<Interval> intervals; @IdClass

JPA update many-to-many deleting records

∥☆過路亽.° 提交于 2019-12-06 09:13:35
I have a @ManyToMany relationship between two entities. When I perform an update on the owning side, it appears that JPA deletes all the linked records from my database and re-inserts them. For me this is a problem because I have a MySQL trigger that fires before a record is deleted. Any ideas on how to get around this problem? @Entity public class User { @Id @Column(name="username") private String username; ... @ManyToMany @JoinTable(name="groups", joinColumns= @JoinColumn(name="username", referencedColumnName="username"), inverseJoinColumns=@JoinColumn(name="groupname", referencedColumnName=

JPA 2.0: How to improve performance on bulk insertion through JPA

放肆的年华 提交于 2019-12-06 09:11:53
问题 Example: I have three tables: location, department, employee now lets say location and department are master tables which already has whole data. Now I need to insert 1000 Employees list through JPA. I have relationship with Location and department in Employee Table as well. so now to insert the entry in Employee, following I am doing: for loop...1000 Employee e = new Employee(); e.setId(12); e.setEmpname("ABC"); Location l = null; l = em.find(Location.class, 234); e.setLocation(l);

How to layout Java EE projects using common JPA entities?

风流意气都作罢 提交于 2019-12-06 08:53:51
问题 I have two eclipse Java EE 6 projects packaged in a WAR-file using maven 3. Now they should share JPA entities in a 3rd project among them, since they both use the same database. When doing the research for my question, I found some hints mentioning for example a reference in a persistence.xml to a common jar, but I wasn't successful to make it work. So specifically asked: 1) Does the project, containing the common entities, has a persistence.xml file? If so, how does it differ from the one

One-to-many relationship: Update removed children with JPA 2.0

家住魔仙堡 提交于 2019-12-06 08:46:36
问题 I have a bidirectional one-to-many relationship. 0 or 1 client <-> List of 0 or more product orders . That relationship should be set or unset on both entities: On the client side, I want to set the List of product orders assigned to the client; the client should then be set / unset to the orders chosen automatically. On the product order side, I want to set the client to which the oder is assigned; that product order should then be removed from its previously assiged client's list and added

Many to many association without join table

纵饮孤独 提交于 2019-12-06 08:35:26
问题 I'd like to apply JPA in the following (simplified) database: NODE AUTHORITY ----- ---------- idNode int idAuthorities int nameNode varchar(50) person varchar(255) idAuthorities int rank int PRIMARY KEY (idNode) PRIMARY KEY (idAuthorities, rank) FOREIGN KEY (idAuthorites) So one node can have multiple authorities and one authority can be referenced by multiple nodes. And I wanted my classes to look like: @Entity @Table(name="NODE") public class Node { private Integer id; private String

@ManyToMany JPA 2 complex query

和自甴很熟 提交于 2019-12-06 07:49:50
问题 I have got the following ManyToMany mapping. @Entity public class Class1 { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "class1_class2", joinColumns = @JoinColumn(name = "class1Id"), inverseJoinColumns = @JoinColumn(name = "class2Id")) private List<Class2> class2; } @Entity public class Class2 { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; } I want to retrieve all the Class1 entities, that

How to control JPA persistence in Wicket forms?

谁都会走 提交于 2019-12-06 06:43:45
问题 I'm building an application using JPA 2.0 (Hibernate implementation), Spring, and Wicket. Everything works, but I'm concerned that my form behaviour is based around side effects. As a first step, I'm using the OpenEntityManagerInViewFilter . My domain objects are fetched by a LoadableDetachableModel which performs entityManager.find() in its load method. In my forms, I wrap a CompoundPropertyModel around this model to bind the data fields. My concern is the form submit actions. Currently my