jpa-2.0

how to define <element-collection> for a List<String> field?

二次信任 提交于 2019-12-24 21:43:40
问题 If my object has a protected List<String> fileNote; What is the right way to define that relationship in an orm.xml? (note: I do not want to use annotations.) 回答1: Most simple, if you are satisfied with defaults is: <element-collection name="fileNote"/> If more customization is needed, you can go further: <element-collection name="fileNote" fetch="EAGER" access="FIELD/> <column name="some_name_for_column_that_holds_note" /> <collection-table name="descriptive_name_for_table"> <join-column

Spring boot JPA & Criteria API - Select single column

寵の児 提交于 2019-12-24 18:31:09
问题 I am trying to retrieve a single column from the table, but I am getting compilation error about return type. SQL select oComment from comment where oNote = note and version > 0; I have Comment table and Note table. Comment table has comment, note and version columns. The comment itself is a note. Now I want to retrieve all comments of the note which has version greater than 0. But here I want only comment column which of note type. Comment.java @Entity @Table(name="comment") @Cache(usage

EntityManagerFactory not being injected using @PersistenceUnit

送分小仙女□ 提交于 2019-12-24 16:25:02
问题 I'm a java beginner. I'm in trouble to configure a persistance unit using JTA transactions. I need to use a PostgreSQL database that is already defined, configured and populated. Using netbeans, i created the persistance.xml and glassfish-resources.xml as fallows: <persistence version="2.0" 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://java.sun.com/xml/ns/persistence

JPA: How to filter an association?

房东的猫 提交于 2019-12-24 14:32:33
问题 My model: @Entity class Person { @Id long id; @OneToMany Set<Employment> employments = new HashSet<Employment>(); } @Entity class Employment { @Id long id; @ManyToOne Company company; Date from; Date until; } It's an association between a Person and a Company that's restricted by a time interval. I'm looking for a JPA criteria query to select all Person s and their employments at a given time. The expected result is a List<Person> containing all people, where the collection employments of

hql inner join Path expected for join! error

懵懂的女人 提交于 2019-12-24 12:12:44
问题 hi have following entities; @Entity public class FilesInfo { @Id @GeneratedValue private Integer id; private String name; private String url; @OneToMany(cascade= CascadeType.ALL) @JoinColumn(name="fileId") private Collection<FilesShare> filesShared = new ArrayList<FilesShare>(); public Collection<FilesShare> getFilesShared() { return filesShared; } public void setFilesShared(Collection<FilesShare> filesShared) { this.filesShared = filesShared; } //getters & setters } the other one @Entity

JPA mapping to Oracle user defined types

不羁岁月 提交于 2019-12-24 10:26:20
问题 Oracle allows for the definition of user defined types. Hibernate can map to these types using the org.hibernate.usertype.UserType class. This defines a mapping between a java bean and the Oracle type. Using straight JPA, how would one do the same thing? 回答1: You cannot do it with straight JPA. It doesn't have concept of user defined type. For this need you have to use vendor extensions. 来源: https://stackoverflow.com/questions/8823855/jpa-mapping-to-oracle-user-defined-types

Generating correct and or condition with JPA Criteria API

三世轮回 提交于 2019-12-24 07:53:30
问题 I am trying to generate query with multiple brackets in 'or' and 'and' conditions but internal brackets are not getting generated. Brackets for outer predicates are generating properly but not for internal ones. Code: CriteriaBuilder criteriaBuilder = this.getEntityManager().getCriteriaBuilder(); CriteriaQuery<ConfigurationKey> query = criteriaBuilder.createQuery(ConfigurationKey.class); Root<ConfigurationKey> configurationKeyRoot = query.from(ConfigurationKey.class); Join<ConfigurationKey,

How to specify a jdbc.url in the persistence.xml relative to the application folder?

大城市里の小女人 提交于 2019-12-24 07:29:08
问题 Once I deploy my application with JPA the user chooses to install it somewhere. Then however the property set as: <property name="javax.persistence.jdbc.url" value="jdbc:derby:db;create=true"/> gets interpreted into the following exception: couldn't create database in \db. Throughout development it used to be the relative path to the project folder, and not the root as it's now. What should I do to make the path remain relative to the folder in which the application is installed? Or at the

JPA query returns proxied entities

假如想象 提交于 2019-12-24 06:38:55
问题 Suppose I have 2 entities, EntityA and EntityB. EntityB is @OneToOne related to EntityA: @Entity public class EntityB { @OneToOne(fetch = FetchType.LAZY) private EntityA entA; // other stuff } When I load EntityB from DB, the corresponding EntityA (say entA1 ) is lazy loaded. After that I load EntityA list by List result = entityManager.createQuery("select A from EntityA A") .setFirstResult(start).setMaxResults(end).getResultList(); The result list contains both previously lazy loaded and

Hibernate ManyToMany with one composite primary key

烂漫一生 提交于 2019-12-24 03:54:09
问题 I've got a problem creating a simple ManyToMany mapping with hibernate anotations. Table PAGE has a composite primary key. +==============+ +================+ +==============+ | PAGE | | PAGE_USER | | USER | +--------------+ 1 0..* +----------------+ 0..* 1 +--------------+ | pageid (pk) |-----------| pageid (pk) |----------| userid (pk) | | entityid (pk)| | entityid (pk) | | ... | | ... | | userid (pk) | | | +==============+ +================+ +==============+ I solved the composite primary