jpa-2.0

JPA/EclipseLink - Retrieve Columns Names

為{幸葍}努か 提交于 2019-12-30 07:12:11
问题 I'm trying to update my knowledge in Java, since I last used in when it was in 1.4.X version... I'm trying to use 1.6.0, in particular the Java Persistence API (2.0). I managed to create an entity class. It's working, since I'm able to store and retrieve data. But I was fooling around and when I decided to fill a JList with the column names of a table and didn't got success... It's a simple class and looks like: @Entity @Table(name = "T_CURRENCY", schema = "APP") public class Currency

Criteria API: filter by class type

佐手、 提交于 2019-12-30 06:58:26
问题 I'm relativley new to relational databases and I have some problems concerning the creation of queries. First I want to explain the situation shortly. I have several entity classes. All of them extend AbstractEntity or EntityProperty . So entities can have properties and properties have owning entities, so there is a bidirectional relation. Now let's say ConcreteEntity extends AbstractEntity and I want to create queries like this: Get all entities of type ConcreteEntity which has at least on

SELECT DISTINCT + ORDER BY in JPA 2 Criteria API

回眸只為那壹抹淺笑 提交于 2019-12-30 06:09:43
问题 I've a class Lawsuit , that contains a List<Hearing> , each one with a Date attribute. I need to select all the Lawsuit s ordered by the date of their Hearing s I've a CriteriaQuery like CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Lawsuit> cq = cb.createQuery(Lawsuit.class); Root<Lawsuit> root = cq.from(Lawsuit.class); I use distinct to flatten the results: cq.select(root).distinct(true); I then join Lawsuit with Hearing Join<Lawsuit, Hearing> hearing = root.join("hearings",

SELECT DISTINCT + ORDER BY in JPA 2 Criteria API

ⅰ亾dé卋堺 提交于 2019-12-30 06:09:05
问题 I've a class Lawsuit , that contains a List<Hearing> , each one with a Date attribute. I need to select all the Lawsuit s ordered by the date of their Hearing s I've a CriteriaQuery like CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Lawsuit> cq = cb.createQuery(Lawsuit.class); Root<Lawsuit> root = cq.from(Lawsuit.class); I use distinct to flatten the results: cq.select(root).distinct(true); I then join Lawsuit with Hearing Join<Lawsuit, Hearing> hearing = root.join("hearings",

SELECT DISTINCT + ORDER BY in JPA 2 Criteria API

夙愿已清 提交于 2019-12-30 06:09:03
问题 I've a class Lawsuit , that contains a List<Hearing> , each one with a Date attribute. I need to select all the Lawsuit s ordered by the date of their Hearing s I've a CriteriaQuery like CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Lawsuit> cq = cb.createQuery(Lawsuit.class); Root<Lawsuit> root = cq.from(Lawsuit.class); I use distinct to flatten the results: cq.select(root).distinct(true); I then join Lawsuit with Hearing Join<Lawsuit, Hearing> hearing = root.join("hearings",

OneToMany - what are the differences between join table and foreign key?

£可爱£侵袭症+ 提交于 2019-12-30 04:29:04
问题 There is the possibility to disable the @OneToMany relationship join table with the @JoinColumn annotation. The default is a join table. What are the advantages and disadvantages for a production system for example? When should I use a join table and when not? Thank you. 回答1: By default @OneToMany will create a join table only if you'll use unidirectional relationship . In other words, if you have Employee and Project entities and the Employee entity is defined as follows (assume there is no

What are the differences between Hibernate and JPA?

北慕城南 提交于 2019-12-30 04:11:27
问题 When i was in college learning about web programming, they told us about hibernate. We used it for a while, i even had the chance to work with it in a real scenario in a company for almost 8 months. Now that i completely switching to Java EE 6 ( Im in love :) ), I use JPA for my ORM needs. It is being a few months since i use it, but i dont really understand what are the differences between one and other. Why some people say one or other is better or worse? The way i do my mappings and

Orphans remain in database even with orphanRemoval=true on one-to-many relationship (JPA/Hibernate)

北城余情 提交于 2019-12-30 04:06:06
问题 @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Table(name = "company_policies") @DiscriminatorColumn(name = "rule_name") public abstract class AbstractPolicyRule implements Serializable { @Transient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; private String value; ... } _ @Entity public class Category implements Serializable { @Transient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @Column(name

Using HSQL in-memory database as JPA datasource

a 夏天 提交于 2019-12-30 03:42:27
问题 I have an in-memory data source: java.sql.Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:testdb", "sa", ""); emf = Persistence.createEntityManagerFactory("manager"); But now I'm stuck. I want to use it as a JPA data source in a J2SE application. I've scoured the entire web but all info is related to J2EE. <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http

JPA Self Join using JoinTable

萝らか妹 提交于 2019-12-29 09:36:06
问题 I have 1 entity call Item in which I want to be able to link parent items to children. to use a join table to create a parent/child relationship. I haven't been able to get any good documentation on. So if anyone has any thoughts I'm all ears. Here is what I have... which works most of the time. public class Item implements java.io.Serializable { @Id private Long id; @ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinTable(name = "ITEMTOITEM", joinColumns = { @JoinColumn(name = "ITEMID"