jpa-2.0

Is there a way to give persistenceUnitName for Spring's LocalContainerEntityManagerFactoryBean without persistence.xml?

倾然丶 夕夏残阳落幕 提交于 2020-01-24 03:06:45
问题 I have multiple datasources and multiple EntityManagerFactories to be defined in my spring context. If there is only on EntityManagerFactory we don't need to give persistenceUnitName. But to associate EntityManager to correct EntityManagerFactory with @PersistenceContext I should give unitName="somePU" attribute. But if we give name for persistenceUnitName attribute then Spring is expecting these persistenceUnitName declarations in persistence.xml file. Is there a way to give

JPA - using long array in IN operator throws cast exception

匆匆过客 提交于 2020-01-23 13:13:10
问题 am new to JPA and am able to get it quickly, I had been trying a select query using "IN" operator in the query and had been getting the error as down. What I do is, i get a array of (long) message ids from a function and i use it to select the record based on those ids. Here is my query select t from MessageTable t where t.messageId IN (:id) query.setParameter("id", id); I had just shown you part of the code, in entity messageId is long and in Oracle DB its number. When i try as just as long

kotlin: some problems with arrays in annotations

你离开我真会死。 提交于 2020-01-23 10:53:21
问题 I have a some problem in annotations: Entity Table(uniqueConstraints = array(UniqueConstraint(columnNames = array("key", "userid")))) public class ... In this case I get the following error: Type inference failed. Expected type mismatch: found: kotlin.Array required: kotlin.String There is no problems with uniqueConstraints = array(...) but Idea shows me error in columnNames = array(...) I using hibernate-jpa-2.1-api-1.0.0.Final.jar Workaround : Instead uniqueConstraints I using composite key

kotlin: some problems with arrays in annotations

心不动则不痛 提交于 2020-01-23 10:53:12
问题 I have a some problem in annotations: Entity Table(uniqueConstraints = array(UniqueConstraint(columnNames = array("key", "userid")))) public class ... In this case I get the following error: Type inference failed. Expected type mismatch: found: kotlin.Array required: kotlin.String There is no problems with uniqueConstraints = array(...) but Idea shows me error in columnNames = array(...) I using hibernate-jpa-2.1-api-1.0.0.Final.jar Workaround : Instead uniqueConstraints I using composite key

How can we use JPA2 (Hibernate) entities as DTO's between two webapps?

删除回忆录丶 提交于 2020-01-23 07:08:26
问题 Hi guys We're running on Glassfish 3.0.1 and using Hibernate 3.5.3. Our project setup looks like this: frontend.war common.jar backend.war We would like to put our jpa2 annotated entities in common.jar in such a way that the backend treats these as JPA2 entities, but the frontend should only see these as POJO's/DTO's. We thought this could be accomplished bu putting persistence.xml in backend.war and having no persistence.xml in the frontend. This doesn't work, after starting up the backend

Removing childs from @OneToMany-association: CascadeType.ALL + orphanRemoval = true not working

≯℡__Kan透↙ 提交于 2020-01-22 09:37:25
问题 I'm having a hard time removing childs from a OneToMany-association. My entities: @Entity @Table(name = "PERSON") public class PersonEntity extends BaseVersionEntity<Long> implements Comparable<PersonEntity> { ... // bi-directional many-to-one association to Project @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "person", orphanRemoval = true) private final Set<ProjectEntity> projects = new HashSet<ProjectEntity>(); ... @Entity @Table(name = "PROJECT") public class

JPA: Why the annotations are applied on getter or field

99封情书 提交于 2020-01-21 05:12:18
问题 why the jpa annotations are applied on field or on getter methods. if i try to apply the annotations on setter method then compiler generate the error. because compiler ignore the annotation on setter method. what is the reason behind them? 回答1: This is is how it's specified. Per JPA Specification: When field-based access is used, the object/relational mapping annotations for the entity class annotate the instance variables, and the persistence provider runtime accesses instance variables

Does an entity manager create a connection to the database?

不羁的心 提交于 2020-01-21 01:51:09
问题 In my project, I forgot to close the entity manager for each operation. After some time, I got exception due to excessive connections to mysql server. Does this mean that each entity manager establish the connection? What will happen when we forget to close the connection? I have used only one entity manager factory. 回答1: Assuming that you are using an application-managed entity manager, then you are responsible for initializing and closing the entity manager. One the other hand, if you are

How to avoid child of child objects in Spring JPA?

*爱你&永不变心* 提交于 2020-01-16 18:18:13
问题 I am using Spring JPA. I have three entities Student, ClassRoom and School like below @Entity public class Student implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name="id") private int id; @Column(name="name") private String name; @Column(name="name") private int age; ... } @Entity public class ClassRoom implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name="id") private int id; @Column(name="name") private String

Error while deployment java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence

蹲街弑〆低调 提交于 2020-01-16 13:50:50
问题 I am Hibernate 4 Final and Spring 3. When I am deploying an application to Weblogic 10.3.6 using Maven 3 I am getting the following excpetions although I have included hibernate-entitymanager in pom java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <url>http:/