eclipselink

To initialize or not initialize JPA relationship mappings?

孤街醉人 提交于 2019-12-18 18:53:52
问题 In one to many JPA associations is it considered a best practice to initialize relationships to empty collections? For example. @Entity public class Order { @Id private Integer id; // should the line items be initialized with an empty array list or not? @OneToMany(mappedBy="order") List<LineItem> lineItems = new ArrayList<>(); } In the above example is it better to define lineItems with a default value of an empty ArrayList or not? What are the pros and cons? 回答1: JPA itself doesn't care

Execute sql script after jpa/EclipseLink created tables?

烂漫一生 提交于 2019-12-18 15:07:15
问题 is there a possibility to execute an sql script, after EclipseLink generated the ddl? In other words, is it possible that the EclipseLink property "eclipselink.ddl-generation" with "drop-and-create-tables" is used and EclipseLink executes another sql-file (to insert some data into some tables just created) after creating the table definition? I'm using EclipseLink 2.x and JPA 2.0 with GlassFish v3. Or can I init the tables within a java method which is called on the project (war with ejb3)

JPA - Setting entity class property from calculated column?

孤人 提交于 2019-12-18 13:37:20
问题 I'm just getting to grips with JPA in a simple Java web app running on Glassfish 3 (Persistence provider is EclipseLink). So far, I'm really liking it (bugs in netbeans/glassfish interaction aside) but there's a thing that I want to be able to do that I'm not sure how to do. I've got an entity class (Article) that's mapped to a database table (article). I'm trying to do a query on the database that returns a calculated column, but I can't figure out how to set up a property of the Article

Can I replace jaxb.properties with code?

﹥>﹥吖頭↗ 提交于 2019-12-18 13:25:20
问题 I am using some non-standard extensions from EclipseLink's implementation of JAXB, and to enable that implementation, I have to configure it using jaxb.properties. Works well. However, due to a build error, the properties file was not included in the proper place, resulting in the default JAXB being used, which without any errors just continued to parse the XML file, ignoring the non-standard extension, leaving me with a non-working bean. To make this more robust, I'd like to get rid off the

EntityManager trying to insert entities without being prompted

放肆的年华 提交于 2019-12-18 09:35:08
问题 Perhaps I'm over-simplifying this by only giving you a small snippet of code (and I'll post more if that is the case) but I figure, initially, less is better: I have an entity of type Asset which has a field of type Location, which is also an entity. When I set the Location of an Asset I must also set the Location of its children. Location location = asset.getLocation(); em.merge(location); em.flush(); childAsset.setLocation(asset.getLocation()); em.flush(); When I run flush(), I get the

How To modify Eclipselink JPA 2.0 connection retry behavior

◇◆丶佛笑我妖孽 提交于 2019-12-18 06:57:05
问题 How To modify Eclipselink JPA 2.0 connection retry behavior . Eclipselink automatically tries to reconnect it self to database whenever it detects a connection failure this causes swing ui to freeze without any responses until it connects to database . Are there any solution to modify this behavior Ie is it possible to throw exception when connection fails without retrying Please help on this issue I am facing with huge problem. I went throe eclipselink source code and google but I could not

EclipseLink MOXy JSON Serialization

☆樱花仙子☆ 提交于 2019-12-18 05:51:36
问题 I have got a sample class: class Zoo { public Collection<? extends Animal> animals; } When serialized with MOXy, I am getting: { "bird": [ { "name": "bird-1", "wingSpan": "6 feets", "preferredFood": "food-1" } ], "cat": [ { "name": "cat-1", "favoriteToy": "toy-1" } ], "dog": [ { "name": "dog-1", "breed": "bread-1", "leashColor": "black" } ] } Why is it using array indicators "[]", while bird, cat, and dog are not arrays? Second, is there a way to get rid of "bird", "cat", and "dog"? In other

Cannot use an EntityTransaction while using JTA

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 05:42:33
问题 I'm receiving this error: javax.servlet.ServletException: java.lang.IllegalStateException: Exception Description: Cannot use an EntityTransaction while using JTA. While trying to use JPA and JAVAEE, Glassfish. My persistence.xml file is as follow: <?xml version="1.0" encoding="UTF-8"?> <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

Cannot use an EntityTransaction while using JTA

北城余情 提交于 2019-12-18 05:41:11
问题 I'm receiving this error: javax.servlet.ServletException: java.lang.IllegalStateException: Exception Description: Cannot use an EntityTransaction while using JTA. While trying to use JPA and JAVAEE, Glassfish. My persistence.xml file is as follow: <?xml version="1.0" encoding="UTF-8"?> <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

How to use MySQL's full text search from JPA

狂风中的少年 提交于 2019-12-18 03:44:07
问题 I want to use MySQL's full text search features using JPA, without having to use a native query. I am using EclipseLink, which has a function to support native SQL commands: FUNC. However, the help examples only show this being use with simple MySQL functions. My best effort attempt to get it to work with MATCH & AGAINST is as follows: @PersistenceContext(name="test") EntityManager em; Query query = em.createQuery("SELECT person FROM People person WHERE FUNC('MATCH', person.name) FUNC(