eclipselink

Eclipselink update existing tables

China☆狼群 提交于 2019-12-03 08:25:53
问题 Maybe I got it wrong but i though that JPA was able to update an existing table (model changed adding a column) but is not working in my case. I can see in the logs eclipselink attempting to create it but failing because it already exists. Instead of trying an update to add the column it keeps going. <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jwrestling"/> <property name="javax.persistence.jdbc.password" value="password"/> <property name="javax.persistence

Access JPA <persistence-unit-metadata> programmatically

梦想与她 提交于 2019-12-03 07:43:27
is it possible to access the information in <persistence-unit-metadata> through Java API? <persistence-unit-metadata> <persistence-unit-defaults> <schema>MySchema</schema> </persistence-unit-defaults> </persistence-unit-metadata> I would like to read the schema "MySchema" via JPA API or EclipseLink API, which is the implementation I use. Something like: entityManager.getDefaults().getSchema(); It's OK to cast or use any EclipseLink class, that's fine for this. Thank you After debugging for a while I found a solution to access the schema of an entity. EntityType<MyEntity> entity = emf

JPA / EclipseLink - create script source with one SQL statement taking multiple lines

半世苍凉 提交于 2019-12-03 06:17:19
I want to let the persistence provider (EclipseLink 2.5.0) automatically create the tables in the, already existing, database by using the persistence unit property "javax.persistence.schema-generation.create-script-source" and a valid SQL-DDL-script. persistence.xml: <property name="javax.persistence.schema-generation.create-script-source" value="data/ddl.sql"/> ddl.sql: USE myDatabase; CREATE TABLE MyTable ( id INTEGER NOT NULL AUTO_INCREMENT, myColumn VARCHAR(255) NOT NULL, PRIMARY KEY (id) ) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8 DEFAULT COLLATE = utf8_bin; But I got the following

JPA Enum ORDINAL vs STRING

谁说我不能喝 提交于 2019-12-03 05:28:13
问题 It's possible to define enumerations in JPA using either @Enumerated(EnumType.ORDINAL) or @Enumerated(EnumType.STRING) I wonder what are advantages and disadvantages of those two definitions? I heard that ORDINAL performs better (is faster) than STRING with EclipseLink. Is that true? 回答1: I always go STRING . Speed is rarely the most important issue - readability and maintainability are more important. I use STRING because it's a lot easier to manually inspect rows from the database, but more

Registering Converters in JPA 2.1 with EclipseLink

僤鯓⒐⒋嵵緔 提交于 2019-12-03 05:06:54
On JavaEE environment, I use JPA 2.1 implementation with EclipseLink, I have some entities that contain enums . So I have created converters for these enumerations. Car entity : @Entity public class Car implements Serializable { private static final long serialVersionUID = 6L; @Id private String id; @Convert (converter = CarColorConverter.class) private CarColor color; public enum CarColor { Black, Gray, White, Red }; public Car () { id = GenerateUUID.id (); } .... } CarColor Converter : @Converter (converterClass = CarColorConverter.class, name = "CarColorConverter") public class

Hibernate or EclipseLink for JPA? [closed]

最后都变了- 提交于 2019-12-03 04:20:09
I was wondering if anyone has experience with the JPA2.0 implementation of any of those frameworks? Especially together with Spring3.x which comes with EclipseLink support. Do you use any of those frameworks and JPA2.0 for production? Any severe issues? Peter Krogh IMHO It is always better to use a standard api where possible. Your own example shows this perfectly. You were able to try your identical code on two providers when one failed to work as expected. Switching to any native API prevents you from doing this. If using EclipseLink as your JPA 2.0 provider works well for you, then use it.

persistence.xml for multiple persistence units

你。 提交于 2019-12-03 03:27:33
I'm trying to persist the same entity to both MySQL and Postgres databases (this is primarily to identify any inconsistencies, and work out the details of any issues doing the dual-write -- which I've run into here). The articles I've found have all described solutions that depend on additional frameworks. I'm trying to solve this using Glassfish 4.0 out-of-the-box, JPA 2.1 with EclipseLink 2.5 as the JPA provider. I'm using Eclipse, and realize that the IDE doesn't support configuring multiple persistence units in the persistence.xml file, so I'm writing the XML for that directly. I was

How to implement a temporal table using JPA?

二次信任 提交于 2019-12-03 03:10:31
问题 I would like to know how to implement temporal tables in JPA 2 with EclipseLink. By temporal I mean tables who define validity period. One problem that I'm facing is that referencing tables can no longer have foreign keys constraints to the referenced tables (temporal tables) because of the nature of the referenced tables which now their primary keys include the validity period. How would I map the relationships of my entities? Would that mean that my entities can no longer have a

Eclipselink update existing tables

十年热恋 提交于 2019-12-02 22:06:27
Maybe I got it wrong but i though that JPA was able to update an existing table (model changed adding a column) but is not working in my case. I can see in the logs eclipselink attempting to create it but failing because it already exists. Instead of trying an update to add the column it keeps going. <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jwrestling"/> <property name="javax.persistence.jdbc.password" value="password"/> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="javax.persistence.jdbc.user" value="user"/

How to silently truncate strings while storing them when they are longer than the column length definition?

南楼画角 提交于 2019-12-02 18:51:57
I have a web app, using EclipseLink and MySQL for storing data. Some of these data are strings, ie varchars in the DB. In the code of entities, the strings have attributes like this: @Column(name = "MODEL", nullable = true, length = 256) private String model; The database is not created by eclipseLink from the code, but the length matches the varchar length in the DB. When the length of such a string data is greater than the length attribute, an exception is raised during the call to javax.persistence.EntityTransaction.commit(): javax.persistence.RollbackException: Exception [EclipseLink-4002]