Embedded entity results in additional column in generated sql when @Column is
used
----------------------------------------------------------------------------------
Key: OPENJPA-1017
URL: https://issues.apache.org/jira/browse/OPENJPA-1017
Project: OpenJPA
Issue Type: Bug
Environment: Postgres 8.2
WinXP SP3
Java 5.0
openjpa-1.2.1-r752877
Reporter: Christopher Gorge A. Marges
I have the following entities:
@Embeddable
public class Amount {
public static int SCALE = 2;
public static int ROUNDING_MODE = BigDecimal.ROUND_HALF_UP;
@Column(nullable = false)
private Currency currency;
@Column(nullable = false)
private BigDecimal value = new BigDecimal("0.00");
//getters and setters follow
}
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Payment implements Serializable {
@SequenceGenerator(name="payment_id_gen",sequenceName="tbl_payment_id_seq",
allocationSize=1)
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE,
generator="payment_id_gen")
private Long id;
@Column(nullable = false)
@Embedded
@AttributeOverrides( {
@AttributeOverride(name = "currency",
column = @Column(name="payment_currency") ),
@AttributeOverride(name = "value",
column = @Column(name="payment_value") )
})
private Amount amount;
//getters and setters follow
}
@Entity
@Table(name = "tbl_cash")
public class Cash extends Payment implements Serializable {
//empty
}
The unit test
public void testPayment() throws Exception {
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("pos");
EntityManager em = emf.createEntityManager();
Query query = em.createQuery("SELECT c FROM Cash c");
Cash cash = (Cash) query.getSingleResult();
...
}
Result is an exception
<openjpa-1.2.1-r752877:753278 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: ERROR: column t0.amount_null
does not exist {prepstmnt 25865024 SELECT t0.id, t0.amount_null,
t0.payment_currency, t0.payment_value FROM tbl_cash t0} [code=0, state=42703]
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:814)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:775)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:771)
at
org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:517)
at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:255)
at
org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:317)
at
com.apollo.arp.pos.library.implementation.PaymentTest.testPayment(PaymentTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: ERROR: column
t0.amount_null does not exist {prepstmnt 25865024 SELECT t0.id, t0.amount_null,
t0.payment_currency, t0.payment_value FROM tbl_cash t0} [code=0, state=42703]
at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:192)
at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:57)
at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeQuery(LoggingConnectionDecorator.java:852)
at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:262)
at
org.apache.openjpa.jdbc.sql.PostgresDictionary$PostgresPreparedStatement.executeQuery(PostgresDictionary.java:520)
at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:262)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeQuery(JDBCStoreManager.java:1595)
at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:252)
at
org.apache.openjpa.jdbc.sql.SelectImpl.executeQuery(SelectImpl.java:496)
at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:384)
at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:339)
at
org.apache.openjpa.jdbc.sql.LogicalUnion$UnionSelect.execute(LogicalUnion.java:420)
at
org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:230)
at
org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:220)
at
org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:206)
at
org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.open(SelectResultObjectProvider.java:94)
at org.apache.openjpa.kernel.QueryImpl.singleResult(QueryImpl.java:1284)
at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1221)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:990)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:805)
... 24 more
Note that column t0.amount_null is not a valid column. To make the query work
this should be removed so the result would be:
SELECT t0.id, t0.payment_currency, t0.payment_value FROM tbl_cash t0.
The column does not appear when the @Column is commented.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.