openjpa

how to use enum with jpa as a data member of persisted entity?

◇◆丶佛笑我妖孽 提交于 2020-01-13 03:33:06
问题 Please best practice and 'how to' for using enum with jpa as a data member of persisted entity. what is the best practice? I want to persist "C", "O" from enum. (codes). If this is not the correct approach please suggest. Enum defination is -- public enum Status{ CLOSED ("C") OPEN ("O") private final int value; private Status(final int pValue){ this.value = pValue; } public int value(){ return this.value; } 回答1: expected Solution: enum defination: public enum Status { CLOSED(1), NEW(2),

Handle expection when an invalid database is configured using spring jpa

瘦欲@ 提交于 2020-01-07 09:04:20
问题 We have an application which reads data from a database. We are using Spring JPA (OpenJPA implementation) to interact with the database. Currently We got an error if the database details is invalid. When an invalid database is configured, how can we handle the expection without crash our application. Please find below the configuration class and the Persistance.xml file that we use. JPA MSSQL configuration class @Configuration @Profile("MSSQL") @EnableTransactionManagement

Cannot run static enhancement of OpenJPA entities with Spring Boot

人走茶凉 提交于 2020-01-05 06:29:50
问题 mvn package fails at the openjpa-maven-plugin:enhance stage when I try to enhance my JPA entities in a Spring Boot app. There's a long error description enhance failed: MetaDataFactory could not be configured (conf.newMetaDataFactoryInstance() returned null). no configuration properties were found. It lists some reasons: Ensure that you have a META-INF/persistence.xml file, that it is available in your classpath I'm using spring-data-jpa with Java config, and there's no persistence.xml . Is

Cannot run static enhancement of OpenJPA entities with Spring Boot

瘦欲@ 提交于 2020-01-05 06:29:15
问题 mvn package fails at the openjpa-maven-plugin:enhance stage when I try to enhance my JPA entities in a Spring Boot app. There's a long error description enhance failed: MetaDataFactory could not be configured (conf.newMetaDataFactoryInstance() returned null). no configuration properties were found. It lists some reasons: Ensure that you have a META-INF/persistence.xml file, that it is available in your classpath I'm using spring-data-jpa with Java config, and there's no persistence.xml . Is

Does OpenJPA work with OSGi

给你一囗甜甜゛ 提交于 2020-01-05 03:51:09
问题 The software we work on is fully on OSGi. So we need JPA implementation which can WELL work with OSGI. Currently we use eclipselink (2.6.3)+eclipse gemini. The problem is that according to specs (jpa or osgi-ee ?) entities are not supported to be in different bundles. However, the developer of gemini said that he also doesn't understand this issue with specs and finds it strange that's why he allowed using entities from different bundles, although no special work was done. So eclipselink

How to cascade delete entities with unidirectional 'ManyToOne' relationship with JPA

穿精又带淫゛_ 提交于 2020-01-04 04:15:12
问题 I have two entity classes 'User' and 'Department' with unidirectional 'ManyToOne' relationship as below. public class User{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "DEPARTMENT_ID", nullable = true) private Department department; } public class Department{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; } If I want to delete some users and cascade remove the

Is a method in a JPA entity allowed to throw an Exception?

自闭症网瘾萝莉.ら 提交于 2020-01-02 09:21:31
问题 I have a problem with an @Entity I am trying to create. The problem arises when trying to test the class in Eclipse using an OpenJPA implementation (I have not tried others so not sure if it might work with them). My test case is simple enough in that it creates an EntityManagerFactory (which automatically finds the persistence.xml on my classpath) and then it tries to create an EntityManager from the factory. This is when I get hit with a very ambiguous 'PersistenceException: null' error.

How can I use typcasting inside a JPQL statement?

故事扮演 提交于 2020-01-02 03:23:23
问题 I have two Integer columns in the database (derby and db2). I need to divide them with each other inside a JPQL . Both columns being of type Integer return zero if remainder is a decimal number e.g 0.25 becomes 0 etc and understandably so since type is int. In SQL I could have this for example select CAST(column1 as decimal(6,2))/CAST(column2 as decimal(6,2))from Sometable; but what is JPQL equivalent . One option might be (I have not tried yet) is to have a @Transient method in the entity

openJPA on Java SE

谁说我不能喝 提交于 2020-01-01 11:45:15
问题 I try to develop JPA project on ibm RAD. And i can run it on Webpshere successfully, but the problem is my machine is quite old. So deploying in Java EE container isn't reasonable.And i want to run it on JSE.But it gives following error: 94 test INFO [main] openjpa.Runtime - Starting OpenJPA 1.2.1-SNAPSHOT 235 test INFO [main] openjpa.jdbc.JDBC - Using dictionary class "com.ibm.ws.persistence.jdbc.sql.DB2Dictionary". 1797 test WARN [main] openjpa.Enhance - This configuration disallows runtime

Database sharding and JPA

夙愿已清 提交于 2020-01-01 04:23:25
问题 I am working on a Java application that requires horizontal partitioning of data in different PostgreSQL servers. I would like to use a JPA framework and Spring for transaction management. The most popular frameworks for sharding data with JPA seem to be Hibernate Shards, which appears to be no longer in development, and OpenJPA Slice, which does not support virtual shards (one of my requirements). Are there any other options that I'm missing, or a way to get around the OpenJPA limitation?