You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Jeremy Bauer (JIRA)" <ji...@apache.org> on 2008/09/25 19:31:44 UTC
[jira] Created: (OPENJPA-733) Entity contains pseudo-attached
embeddable after detach
Entity contains pseudo-attached embeddable after detach
-------------------------------------------------------
Key: OPENJPA-733
URL: https://issues.apache.org/jira/browse/OPENJPA-733
Project: OpenJPA
Issue Type: Bug
Components: kernel
Affects Versions: 1.2.0
Reporter: Jeremy Bauer
Problem reported by Chris Tillman on user forum and can be easily reproduced with the code provided:
When upgrading a standalone Java application from OpenJPA 1.1 to 1.2 i ran
into a problem regarding embedded classes.
Accessing a field from an embedded class (say, Address) in a detached entity
(Customer) doesn't seem to work anymore. OpenJPA 1.2 throws an
InvalidStateException. It worked fine with OpenJPA 1.1.
The field (street) contains the correct value as loaded from the database,
but when the getter is used, e.g. customer.getAddress().getStreet(), the ISE
is thrown:
org.apache.openjpa.persistence.InvalidStateException: The context has been
closed.
at org.apache.openjpa.kernel.BrokerImpl.assertOpen(BrokerImpl.java:4367)
at
org.apache.openjpa.kernel.BrokerImpl.beginOperation(BrokerImpl.java:1766)
at org.apache.openjpa.kernel.BrokerImpl.isActive(BrokerImpl.java:1736)
at
org.apache.openjpa.kernel.StateManagerImpl.beforeRead(StateManagerImpl.java:941)
at
org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1476)
at org.test.Address.pcGetstreet(Address.java)
at org.test.Address.getStreet(Address.java:22)
at org.test.Test.main(Test.java:30)
Upon investigation, it seems to work OK in OpenJPA 1.2 using runtime
enhancement (Java 6) but not using compile-time enhancement. However, in
OpenJPA 1.1 it's the other way around.
OpenJPA 1.1 with compile-time enhancement uses a DetachedStateManager for
both the entity and the embeddable. As can be seen from the stacktrace,
OpenJPA 1.2 uses a StateManagerImpl instead for the embeddable.
Is this a regression in OpenJPA 1.2?
Test code below:
//-------------------------
package org.test;
import java.util.List;
import javax.persistence.*;
public class Test {
public static void main(String[] args) {
EntityManagerFactory factory = Persistence
.createEntityManagerFactory("test");
Customer customer = new Customer();
Address address = new Address();
customer.setLastName("Doe");
address.setStreet("Main Street");
customer.setAddress(address);
try {
persistCustomer(factory, customer);
customer = queryCustomers(factory,
"select customer from Customer customer" +
" where customer.lastName = 'Doe'")
.get(0);
System.out.println(customer.getLastName());
System.out.println(customer.getAddress().getStreet());
factory.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
static void persistCustomer(EntityManagerFactory factory, Customer
customer)
throws Exception {
final EntityManager em = factory.createEntityManager();
final EntityTransaction tx = em.getTransaction();
tx.begin();
try {
em.persist(customer);
tx.commit();
} finally {
if (!tx.isActive()) {
em.close();
}
}
}
public static List<Customer> queryCustomers(EntityManagerFactory factory,
String query) throws Exception {
final EntityManager em = factory.createEntityManager();
final EntityTransaction tx = em.getTransaction();
tx.begin();
try {
final List<Customer> list = (List<Customer>) em.createQuery(query)
.getResultList();
tx.commit();
return list;
} finally {
if (!tx.isActive()) {
em.close();
}
}
}
}
//-------------------------
package org.test;
import javax.persistence.*;
@Entity
public class Customer {
@Id @GeneratedValue long id;
@Basic String lastName;
@Embedded Address address;
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
//-------------------------
package org.test;
import javax.persistence.*;
@Embeddable
public class Address {
@Basic String street;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (OPENJPA-733) Entity contains pseudo-attached
embeddable after detach
Posted by "Michael Dick (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-733?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Michael Dick updated OPENJPA-733:
---------------------------------
Fix Version/s: 1.2.1
Considering for 1.2.1
> Entity contains pseudo-attached embeddable after detach
> -------------------------------------------------------
>
> Key: OPENJPA-733
> URL: https://issues.apache.org/jira/browse/OPENJPA-733
> Project: OpenJPA
> Issue Type: Bug
> Components: kernel
> Affects Versions: 1.2.0
> Reporter: Jeremy Bauer
> Assignee: Jeremy Bauer
> Fix For: 1.2.1, 1.3.0
>
> Attachments: OPENJPA-733.patch
>
>
> Problem reported by Chris Tillman on user forum and can be easily reproduced with the code provided:
> When upgrading a standalone Java application from OpenJPA 1.1 to 1.2 i ran
> into a problem regarding embedded classes.
> Accessing a field from an embedded class (say, Address) in a detached entity
> (Customer) doesn't seem to work anymore. OpenJPA 1.2 throws an
> InvalidStateException. It worked fine with OpenJPA 1.1.
> The field (street) contains the correct value as loaded from the database,
> but when the getter is used, e.g. customer.getAddress().getStreet(), the ISE
> is thrown:
> org.apache.openjpa.persistence.InvalidStateException: The context has been
> closed.
> at org.apache.openjpa.kernel.BrokerImpl.assertOpen(BrokerImpl.java:4367)
> at
> org.apache.openjpa.kernel.BrokerImpl.beginOperation(BrokerImpl.java:1766)
> at org.apache.openjpa.kernel.BrokerImpl.isActive(BrokerImpl.java:1736)
> at
> org.apache.openjpa.kernel.StateManagerImpl.beforeRead(StateManagerImpl.java:941)
> at
> org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1476)
> at org.test.Address.pcGetstreet(Address.java)
> at org.test.Address.getStreet(Address.java:22)
> at org.test.Test.main(Test.java:30)
> Upon investigation, it seems to work OK in OpenJPA 1.2 using runtime
> enhancement (Java 6) but not using compile-time enhancement. However, in
> OpenJPA 1.1 it's the other way around.
> OpenJPA 1.1 with compile-time enhancement uses a DetachedStateManager for
> both the entity and the embeddable. As can be seen from the stacktrace,
> OpenJPA 1.2 uses a StateManagerImpl instead for the embeddable.
> Is this a regression in OpenJPA 1.2?
> Test code below:
> //-------------------------
> package org.test;
> import java.util.List;
> import javax.persistence.*;
> public class Test {
> public static void main(String[] args) {
> EntityManagerFactory factory = Persistence
> .createEntityManagerFactory("test");
> Customer customer = new Customer();
> Address address = new Address();
> customer.setLastName("Doe");
> address.setStreet("Main Street");
> customer.setAddress(address);
> try {
> persistCustomer(factory, customer);
> customer = queryCustomers(factory,
> "select customer from Customer customer" +
> " where customer.lastName = 'Doe'")
> .get(0);
> System.out.println(customer.getLastName());
> System.out.println(customer.getAddress().getStreet());
> factory.close();
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
> static void persistCustomer(EntityManagerFactory factory, Customer
> customer)
> throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> em.persist(customer);
> tx.commit();
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> public static List<Customer> queryCustomers(EntityManagerFactory factory,
> String query) throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> final List<Customer> list = (List<Customer>) em.createQuery(query)
> .getResultList();
> tx.commit();
> return list;
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Entity
> public class Customer {
> @Id @GeneratedValue long id;
> @Basic String lastName;
> @Embedded Address address;
> public String getLastName() {
> return lastName;
> }
> public void setLastName(String lastName) {
> this.lastName = lastName;
> }
> public Address getAddress() {
> return address;
> }
> public void setAddress(Address address) {
> this.address = address;
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Embeddable
> public class Address {
> @Basic String street;
> public String getStreet() {
> return street;
> }
> public void setStreet(String street) {
> this.street = street;
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (OPENJPA-733) Entity contains pseudo-attached
embeddable after detach
Posted by "Jeremy Bauer (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-733?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jeremy Bauer updated OPENJPA-733:
---------------------------------
Attachment: OPENJPA-733_test.patch
OPENJPA-733_smimpl.patch
Attaching clean patches (no EOL issue) for StateManagerImpl and TestEmbedded. I created them with trunk, but was able to successfully apply them to 1.2.x.
> Entity contains pseudo-attached embeddable after detach
> -------------------------------------------------------
>
> Key: OPENJPA-733
> URL: https://issues.apache.org/jira/browse/OPENJPA-733
> Project: OpenJPA
> Issue Type: Bug
> Components: kernel
> Affects Versions: 1.2.0
> Reporter: Jeremy Bauer
> Assignee: Jeremy Bauer
> Fix For: 1.2.1, 1.3.0
>
> Attachments: OPENJPA-733.patch, OPENJPA-733_smimpl.patch, OPENJPA-733_test.patch
>
>
> Problem reported by Chris Tillman on user forum and can be easily reproduced with the code provided:
> When upgrading a standalone Java application from OpenJPA 1.1 to 1.2 i ran
> into a problem regarding embedded classes.
> Accessing a field from an embedded class (say, Address) in a detached entity
> (Customer) doesn't seem to work anymore. OpenJPA 1.2 throws an
> InvalidStateException. It worked fine with OpenJPA 1.1.
> The field (street) contains the correct value as loaded from the database,
> but when the getter is used, e.g. customer.getAddress().getStreet(), the ISE
> is thrown:
> org.apache.openjpa.persistence.InvalidStateException: The context has been
> closed.
> at org.apache.openjpa.kernel.BrokerImpl.assertOpen(BrokerImpl.java:4367)
> at
> org.apache.openjpa.kernel.BrokerImpl.beginOperation(BrokerImpl.java:1766)
> at org.apache.openjpa.kernel.BrokerImpl.isActive(BrokerImpl.java:1736)
> at
> org.apache.openjpa.kernel.StateManagerImpl.beforeRead(StateManagerImpl.java:941)
> at
> org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1476)
> at org.test.Address.pcGetstreet(Address.java)
> at org.test.Address.getStreet(Address.java:22)
> at org.test.Test.main(Test.java:30)
> Upon investigation, it seems to work OK in OpenJPA 1.2 using runtime
> enhancement (Java 6) but not using compile-time enhancement. However, in
> OpenJPA 1.1 it's the other way around.
> OpenJPA 1.1 with compile-time enhancement uses a DetachedStateManager for
> both the entity and the embeddable. As can be seen from the stacktrace,
> OpenJPA 1.2 uses a StateManagerImpl instead for the embeddable.
> Is this a regression in OpenJPA 1.2?
> Test code below:
> //-------------------------
> package org.test;
> import java.util.List;
> import javax.persistence.*;
> public class Test {
> public static void main(String[] args) {
> EntityManagerFactory factory = Persistence
> .createEntityManagerFactory("test");
> Customer customer = new Customer();
> Address address = new Address();
> customer.setLastName("Doe");
> address.setStreet("Main Street");
> customer.setAddress(address);
> try {
> persistCustomer(factory, customer);
> customer = queryCustomers(factory,
> "select customer from Customer customer" +
> " where customer.lastName = 'Doe'")
> .get(0);
> System.out.println(customer.getLastName());
> System.out.println(customer.getAddress().getStreet());
> factory.close();
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
> static void persistCustomer(EntityManagerFactory factory, Customer
> customer)
> throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> em.persist(customer);
> tx.commit();
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> public static List<Customer> queryCustomers(EntityManagerFactory factory,
> String query) throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> final List<Customer> list = (List<Customer>) em.createQuery(query)
> .getResultList();
> tx.commit();
> return list;
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Entity
> public class Customer {
> @Id @GeneratedValue long id;
> @Basic String lastName;
> @Embedded Address address;
> public String getLastName() {
> return lastName;
> }
> public void setLastName(String lastName) {
> this.lastName = lastName;
> }
> public Address getAddress() {
> return address;
> }
> public void setAddress(Address address) {
> this.address = address;
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Embeddable
> public class Address {
> @Basic String street;
> public String getStreet() {
> return street;
> }
> public void setStreet(String street) {
> this.street = street;
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Assigned: (OPENJPA-733) Entity contains pseudo-attached
embeddable after detach
Posted by "Jeremy Bauer (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-733?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jeremy Bauer reassigned OPENJPA-733:
------------------------------------
Assignee: Jeremy Bauer
> Entity contains pseudo-attached embeddable after detach
> -------------------------------------------------------
>
> Key: OPENJPA-733
> URL: https://issues.apache.org/jira/browse/OPENJPA-733
> Project: OpenJPA
> Issue Type: Bug
> Components: kernel
> Affects Versions: 1.2.0
> Reporter: Jeremy Bauer
> Assignee: Jeremy Bauer
>
> Problem reported by Chris Tillman on user forum and can be easily reproduced with the code provided:
> When upgrading a standalone Java application from OpenJPA 1.1 to 1.2 i ran
> into a problem regarding embedded classes.
> Accessing a field from an embedded class (say, Address) in a detached entity
> (Customer) doesn't seem to work anymore. OpenJPA 1.2 throws an
> InvalidStateException. It worked fine with OpenJPA 1.1.
> The field (street) contains the correct value as loaded from the database,
> but when the getter is used, e.g. customer.getAddress().getStreet(), the ISE
> is thrown:
> org.apache.openjpa.persistence.InvalidStateException: The context has been
> closed.
> at org.apache.openjpa.kernel.BrokerImpl.assertOpen(BrokerImpl.java:4367)
> at
> org.apache.openjpa.kernel.BrokerImpl.beginOperation(BrokerImpl.java:1766)
> at org.apache.openjpa.kernel.BrokerImpl.isActive(BrokerImpl.java:1736)
> at
> org.apache.openjpa.kernel.StateManagerImpl.beforeRead(StateManagerImpl.java:941)
> at
> org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1476)
> at org.test.Address.pcGetstreet(Address.java)
> at org.test.Address.getStreet(Address.java:22)
> at org.test.Test.main(Test.java:30)
> Upon investigation, it seems to work OK in OpenJPA 1.2 using runtime
> enhancement (Java 6) but not using compile-time enhancement. However, in
> OpenJPA 1.1 it's the other way around.
> OpenJPA 1.1 with compile-time enhancement uses a DetachedStateManager for
> both the entity and the embeddable. As can be seen from the stacktrace,
> OpenJPA 1.2 uses a StateManagerImpl instead for the embeddable.
> Is this a regression in OpenJPA 1.2?
> Test code below:
> //-------------------------
> package org.test;
> import java.util.List;
> import javax.persistence.*;
> public class Test {
> public static void main(String[] args) {
> EntityManagerFactory factory = Persistence
> .createEntityManagerFactory("test");
> Customer customer = new Customer();
> Address address = new Address();
> customer.setLastName("Doe");
> address.setStreet("Main Street");
> customer.setAddress(address);
> try {
> persistCustomer(factory, customer);
> customer = queryCustomers(factory,
> "select customer from Customer customer" +
> " where customer.lastName = 'Doe'")
> .get(0);
> System.out.println(customer.getLastName());
> System.out.println(customer.getAddress().getStreet());
> factory.close();
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
> static void persistCustomer(EntityManagerFactory factory, Customer
> customer)
> throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> em.persist(customer);
> tx.commit();
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> public static List<Customer> queryCustomers(EntityManagerFactory factory,
> String query) throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> final List<Customer> list = (List<Customer>) em.createQuery(query)
> .getResultList();
> tx.commit();
> return list;
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Entity
> public class Customer {
> @Id @GeneratedValue long id;
> @Basic String lastName;
> @Embedded Address address;
> public String getLastName() {
> return lastName;
> }
> public void setLastName(String lastName) {
> this.lastName = lastName;
> }
> public Address getAddress() {
> return address;
> }
> public void setAddress(Address address) {
> this.address = address;
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Embeddable
> public class Address {
> @Basic String street;
> public String getStreet() {
> return street;
> }
> public void setStreet(String street) {
> this.street = street;
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (OPENJPA-733) Entity contains pseudo-attached
embeddable after detach
Posted by "Jeremy Bauer (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-733?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jeremy Bauer updated OPENJPA-733:
---------------------------------
Attachment: OPENJPA-733.patch
Attaching a preliminary patch for trunk. I've only tested with the submitted test case. I still need to run the full unit test suite. If all tests pass, will convert submitted test to OpenJPA jUnit and commit code changes.
In summary, embeddables were not being added to the L1 cache as the result of a query so they were not processed as part of the detach operation. The StateManagerImpl.getObjectId is a bit misleading since it returns the oid of the owner, not the embeddable. The owner was already in the L1 cache, so the embeddable was not loaded. Modified the logic to check the L1 for the embeddable oid.
> Entity contains pseudo-attached embeddable after detach
> -------------------------------------------------------
>
> Key: OPENJPA-733
> URL: https://issues.apache.org/jira/browse/OPENJPA-733
> Project: OpenJPA
> Issue Type: Bug
> Components: kernel
> Affects Versions: 1.2.0
> Reporter: Jeremy Bauer
> Assignee: Jeremy Bauer
> Attachments: OPENJPA-733.patch
>
>
> Problem reported by Chris Tillman on user forum and can be easily reproduced with the code provided:
> When upgrading a standalone Java application from OpenJPA 1.1 to 1.2 i ran
> into a problem regarding embedded classes.
> Accessing a field from an embedded class (say, Address) in a detached entity
> (Customer) doesn't seem to work anymore. OpenJPA 1.2 throws an
> InvalidStateException. It worked fine with OpenJPA 1.1.
> The field (street) contains the correct value as loaded from the database,
> but when the getter is used, e.g. customer.getAddress().getStreet(), the ISE
> is thrown:
> org.apache.openjpa.persistence.InvalidStateException: The context has been
> closed.
> at org.apache.openjpa.kernel.BrokerImpl.assertOpen(BrokerImpl.java:4367)
> at
> org.apache.openjpa.kernel.BrokerImpl.beginOperation(BrokerImpl.java:1766)
> at org.apache.openjpa.kernel.BrokerImpl.isActive(BrokerImpl.java:1736)
> at
> org.apache.openjpa.kernel.StateManagerImpl.beforeRead(StateManagerImpl.java:941)
> at
> org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1476)
> at org.test.Address.pcGetstreet(Address.java)
> at org.test.Address.getStreet(Address.java:22)
> at org.test.Test.main(Test.java:30)
> Upon investigation, it seems to work OK in OpenJPA 1.2 using runtime
> enhancement (Java 6) but not using compile-time enhancement. However, in
> OpenJPA 1.1 it's the other way around.
> OpenJPA 1.1 with compile-time enhancement uses a DetachedStateManager for
> both the entity and the embeddable. As can be seen from the stacktrace,
> OpenJPA 1.2 uses a StateManagerImpl instead for the embeddable.
> Is this a regression in OpenJPA 1.2?
> Test code below:
> //-------------------------
> package org.test;
> import java.util.List;
> import javax.persistence.*;
> public class Test {
> public static void main(String[] args) {
> EntityManagerFactory factory = Persistence
> .createEntityManagerFactory("test");
> Customer customer = new Customer();
> Address address = new Address();
> customer.setLastName("Doe");
> address.setStreet("Main Street");
> customer.setAddress(address);
> try {
> persistCustomer(factory, customer);
> customer = queryCustomers(factory,
> "select customer from Customer customer" +
> " where customer.lastName = 'Doe'")
> .get(0);
> System.out.println(customer.getLastName());
> System.out.println(customer.getAddress().getStreet());
> factory.close();
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
> static void persistCustomer(EntityManagerFactory factory, Customer
> customer)
> throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> em.persist(customer);
> tx.commit();
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> public static List<Customer> queryCustomers(EntityManagerFactory factory,
> String query) throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> final List<Customer> list = (List<Customer>) em.createQuery(query)
> .getResultList();
> tx.commit();
> return list;
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Entity
> public class Customer {
> @Id @GeneratedValue long id;
> @Basic String lastName;
> @Embedded Address address;
> public String getLastName() {
> return lastName;
> }
> public void setLastName(String lastName) {
> this.lastName = lastName;
> }
> public Address getAddress() {
> return address;
> }
> public void setAddress(Address address) {
> this.address = address;
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Embeddable
> public class Address {
> @Basic String street;
> public String getStreet() {
> return street;
> }
> public void setStreet(String street) {
> this.street = street;
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (OPENJPA-733) Entity contains pseudo-attached
embeddable after detach
Posted by "Jeremy Bauer (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-733?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jeremy Bauer resolved OPENJPA-733.
----------------------------------
Resolution: Fixed
Fix Version/s: 1.3.0
Chris applied the patch and it corrected the problem. Committed in revision 700563. Marking issue as resolved.
> Entity contains pseudo-attached embeddable after detach
> -------------------------------------------------------
>
> Key: OPENJPA-733
> URL: https://issues.apache.org/jira/browse/OPENJPA-733
> Project: OpenJPA
> Issue Type: Bug
> Components: kernel
> Affects Versions: 1.2.0
> Reporter: Jeremy Bauer
> Assignee: Jeremy Bauer
> Fix For: 1.3.0
>
> Attachments: OPENJPA-733.patch
>
>
> Problem reported by Chris Tillman on user forum and can be easily reproduced with the code provided:
> When upgrading a standalone Java application from OpenJPA 1.1 to 1.2 i ran
> into a problem regarding embedded classes.
> Accessing a field from an embedded class (say, Address) in a detached entity
> (Customer) doesn't seem to work anymore. OpenJPA 1.2 throws an
> InvalidStateException. It worked fine with OpenJPA 1.1.
> The field (street) contains the correct value as loaded from the database,
> but when the getter is used, e.g. customer.getAddress().getStreet(), the ISE
> is thrown:
> org.apache.openjpa.persistence.InvalidStateException: The context has been
> closed.
> at org.apache.openjpa.kernel.BrokerImpl.assertOpen(BrokerImpl.java:4367)
> at
> org.apache.openjpa.kernel.BrokerImpl.beginOperation(BrokerImpl.java:1766)
> at org.apache.openjpa.kernel.BrokerImpl.isActive(BrokerImpl.java:1736)
> at
> org.apache.openjpa.kernel.StateManagerImpl.beforeRead(StateManagerImpl.java:941)
> at
> org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1476)
> at org.test.Address.pcGetstreet(Address.java)
> at org.test.Address.getStreet(Address.java:22)
> at org.test.Test.main(Test.java:30)
> Upon investigation, it seems to work OK in OpenJPA 1.2 using runtime
> enhancement (Java 6) but not using compile-time enhancement. However, in
> OpenJPA 1.1 it's the other way around.
> OpenJPA 1.1 with compile-time enhancement uses a DetachedStateManager for
> both the entity and the embeddable. As can be seen from the stacktrace,
> OpenJPA 1.2 uses a StateManagerImpl instead for the embeddable.
> Is this a regression in OpenJPA 1.2?
> Test code below:
> //-------------------------
> package org.test;
> import java.util.List;
> import javax.persistence.*;
> public class Test {
> public static void main(String[] args) {
> EntityManagerFactory factory = Persistence
> .createEntityManagerFactory("test");
> Customer customer = new Customer();
> Address address = new Address();
> customer.setLastName("Doe");
> address.setStreet("Main Street");
> customer.setAddress(address);
> try {
> persistCustomer(factory, customer);
> customer = queryCustomers(factory,
> "select customer from Customer customer" +
> " where customer.lastName = 'Doe'")
> .get(0);
> System.out.println(customer.getLastName());
> System.out.println(customer.getAddress().getStreet());
> factory.close();
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
> static void persistCustomer(EntityManagerFactory factory, Customer
> customer)
> throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> em.persist(customer);
> tx.commit();
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> public static List<Customer> queryCustomers(EntityManagerFactory factory,
> String query) throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> final List<Customer> list = (List<Customer>) em.createQuery(query)
> .getResultList();
> tx.commit();
> return list;
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Entity
> public class Customer {
> @Id @GeneratedValue long id;
> @Basic String lastName;
> @Embedded Address address;
> public String getLastName() {
> return lastName;
> }
> public void setLastName(String lastName) {
> this.lastName = lastName;
> }
> public Address getAddress() {
> return address;
> }
> public void setAddress(Address address) {
> this.address = address;
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Embeddable
> public class Address {
> @Basic String street;
> public String getStreet() {
> return street;
> }
> public void setStreet(String street) {
> this.street = street;
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (OPENJPA-733) Entity contains pseudo-attached
embeddable after detach
Posted by "Jeremy Bauer (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12638632#action_12638632 ]
Jeremy Bauer commented on OPENJPA-733:
--------------------------------------
Here is a link to forum conversation on nabble for reference: http://n2.nabble.com/Problem-with-detaching-embedded-class-in-OpenJPA-1.2-using-compile-time-enhancement-td1117628.html
> Entity contains pseudo-attached embeddable after detach
> -------------------------------------------------------
>
> Key: OPENJPA-733
> URL: https://issues.apache.org/jira/browse/OPENJPA-733
> Project: OpenJPA
> Issue Type: Bug
> Components: kernel
> Affects Versions: 1.2.0
> Reporter: Jeremy Bauer
> Assignee: Jeremy Bauer
> Fix For: 1.2.1, 1.3.0
>
> Attachments: OPENJPA-733.patch, OPENJPA-733_smimpl.patch, OPENJPA-733_test.patch
>
>
> Problem reported by Chris Tillman on user forum and can be easily reproduced with the code provided:
> When upgrading a standalone Java application from OpenJPA 1.1 to 1.2 i ran
> into a problem regarding embedded classes.
> Accessing a field from an embedded class (say, Address) in a detached entity
> (Customer) doesn't seem to work anymore. OpenJPA 1.2 throws an
> InvalidStateException. It worked fine with OpenJPA 1.1.
> The field (street) contains the correct value as loaded from the database,
> but when the getter is used, e.g. customer.getAddress().getStreet(), the ISE
> is thrown:
> org.apache.openjpa.persistence.InvalidStateException: The context has been
> closed.
> at org.apache.openjpa.kernel.BrokerImpl.assertOpen(BrokerImpl.java:4367)
> at
> org.apache.openjpa.kernel.BrokerImpl.beginOperation(BrokerImpl.java:1766)
> at org.apache.openjpa.kernel.BrokerImpl.isActive(BrokerImpl.java:1736)
> at
> org.apache.openjpa.kernel.StateManagerImpl.beforeRead(StateManagerImpl.java:941)
> at
> org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1476)
> at org.test.Address.pcGetstreet(Address.java)
> at org.test.Address.getStreet(Address.java:22)
> at org.test.Test.main(Test.java:30)
> Upon investigation, it seems to work OK in OpenJPA 1.2 using runtime
> enhancement (Java 6) but not using compile-time enhancement. However, in
> OpenJPA 1.1 it's the other way around.
> OpenJPA 1.1 with compile-time enhancement uses a DetachedStateManager for
> both the entity and the embeddable. As can be seen from the stacktrace,
> OpenJPA 1.2 uses a StateManagerImpl instead for the embeddable.
> Is this a regression in OpenJPA 1.2?
> Test code below:
> //-------------------------
> package org.test;
> import java.util.List;
> import javax.persistence.*;
> public class Test {
> public static void main(String[] args) {
> EntityManagerFactory factory = Persistence
> .createEntityManagerFactory("test");
> Customer customer = new Customer();
> Address address = new Address();
> customer.setLastName("Doe");
> address.setStreet("Main Street");
> customer.setAddress(address);
> try {
> persistCustomer(factory, customer);
> customer = queryCustomers(factory,
> "select customer from Customer customer" +
> " where customer.lastName = 'Doe'")
> .get(0);
> System.out.println(customer.getLastName());
> System.out.println(customer.getAddress().getStreet());
> factory.close();
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
> static void persistCustomer(EntityManagerFactory factory, Customer
> customer)
> throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> em.persist(customer);
> tx.commit();
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> public static List<Customer> queryCustomers(EntityManagerFactory factory,
> String query) throws Exception {
> final EntityManager em = factory.createEntityManager();
> final EntityTransaction tx = em.getTransaction();
> tx.begin();
> try {
> final List<Customer> list = (List<Customer>) em.createQuery(query)
> .getResultList();
> tx.commit();
> return list;
> } finally {
> if (!tx.isActive()) {
> em.close();
> }
> }
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Entity
> public class Customer {
> @Id @GeneratedValue long id;
> @Basic String lastName;
> @Embedded Address address;
> public String getLastName() {
> return lastName;
> }
> public void setLastName(String lastName) {
> this.lastName = lastName;
> }
> public Address getAddress() {
> return address;
> }
> public void setAddress(Address address) {
> this.address = address;
> }
> }
> //-------------------------
> package org.test;
> import javax.persistence.*;
> @Embeddable
> public class Address {
> @Basic String street;
> public String getStreet() {
> return street;
> }
> public void setStreet(String street) {
> this.street = street;
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.