openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Henderson <peter.hender...@starjar.com>
Subject @GeneratedValue and schemas
Date Wed, 13 May 2009 22:26:25 GMT
I've an entity bean [1] which maps to a table [2] in a 
specific schema.
The entity bean has an Integer id column which is generated 
using a sequence. The database in question is Postgresql 8.3.x

When I used TopLinkEssentials I could specify
     @GeneratedValue(strategy = GenerationType.IDENTITY)
and the correct sequence was used 
"summary_charts.mappings_layout_chart_mapping_id_seq"

but...

using OpenJPA I get an exception saying sequence 
"mappings_layout_chart_mapping_id_seq" not being found [3]
is this a bug with OpenJPA in that it is not using the 
schema of the table or a bug in my code? Shouldn't OpenJpa 
be looking for a sequence called <schema name>.<table>_<id 
field name>_seq

e.g.
it should be looking for

summary_charts + "." +   // schema name
mappings "_"		 // table name
layout_chart_mapping_id "_seq" // column name

"summary_charts.mappings_layout_chart_mapping_id_seq"




In the mean time I have a work around using
@SequenceGenerator(
 
name="summary_charts.mappings_layout_chart_mapping_id_seq",
 
sequenceName="summary_charts.mappings_layout_chart_mapping_id_seq")

and
     @GeneratedValue(generator = 
"summary_charts.mappings_layout_chart_mapping_id_seq",
                     strategy = GenerationType.SEQUENCE)













Cheers

Peter.






[1] Entity bean
/**
  *
  * @author peter
  */
@Entity
@Table(name = "mappings", schema="summary_charts")
public class SummaryMapping implements Serializable  {
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     @Column(name = "layout_chart_mapping_id", nullable = false)
     private Integer mappingId;

.. SNIP other fields getters/setters/hashcode/equals/toString ..
}

[2] Database table
CREATE SCHEMA summary_charts;

CREATE TABLE summary_charts.mappings
(
   layout_chart_mapping_id serial NOT NULL,
   layout_id integer NOT NULL,
   chart_id integer NOT NULL,
   layout text NOT NULL,
   CONSTRAINT mappings_pkey PRIMARY KEY 
(layout_chart_mapping_id),
   CONSTRAINT mappings_chart_id_fkey FOREIGN KEY (chart_id)
       REFERENCES summary_charts.charts (chart_id) MATCH SIMPLE
       ON UPDATE NO ACTION ON DELETE NO ACTION,
   CONSTRAINT mappings_layout_id_fkey FOREIGN KEY (layout_id)
       REFERENCES summary_charts.layouts (layout_id) MATCH 
SIMPLE
       ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (OIDS=FALSE);
ALTER TABLE summary_charts.mappings OWNER TO dbadmin;



[3] Exception message
<openjpa-1.2.1-r752877:753278 fatal store error> 
org.apache.openjpa.persistence.RollbackException: The 
transaction has been rolled back.  See the nested exceptions 
for details on the errors that occurred.
         at 
org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:523)
         at 
com.starjar.starjarenterprise5.api.ServiceBase.returnEntityManager(ServiceBase.java:98)
         at 
com.starjar.starjarenterprise5.api.SummaryChartService.createSummaryMapping(SummaryChartService.java:80)
         at 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at 
com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:192)
         at 
com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:110)
         at 
com.caucho.hessian.server.HessianServlet.service(HessianServlet.java:416)
         at 
com.starjar.starjarenterprise5.api.ServiceBase.service(ServiceBase.java:107)
         at 
org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
         at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
         at 
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
         at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
         at 
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
         at 
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
         at 
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
         at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
         at 
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
         at 
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
         at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
         at 
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
         at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
         at 
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
         at 
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
         at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
         at 
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
         at 
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
         at 
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
         at 
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
         at 
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
         at 
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
         at 
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
         at 
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
         at 
com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
         at 
com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
         at 
com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Caused by: <openjpa-1.2.1-r752877:753278 fatal general 
error> org.apache.openjpa.persistence.PersistenceException: 
The transaction has been rolled back.  See the nested 
exceptions for details on the errors that occurred.
         at 
org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2163)
         at 
org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2010)
         at 
org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1908)
         at 
org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1679)
         at 
org.apache.openjpa.kernel.DelegatingBroker.flush(DelegatingBroker.java:989)
         at 
org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:592)
         at 
com.starjar.starjarenterprise5.service.helpers.SummaryApi.createSummaryMapping(SummaryApi.java:113)
         at 
com.starjar.starjarenterprise5.api.SummaryChartService.createSummaryMapping(SummaryChartService.java:77)
         ... 35 more
Caused by: <openjpa-1.2.1-r752877:753278 nonfatal general 
error> org.apache.openjpa.persistence.PersistenceException: 
ERROR: relation "mappings_layout_chart_mapping_id_seq" does 
not exist {prepstmnt 1646550480 SELECT 
CURRVAL('mappings_layout_chart_mapping_id_SEQ')} [code=0, 
state=42P01]
         at 
org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4232)
         at 
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4197)
         at 
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:102)
         at 
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:88)
         at 
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:64)
         at 
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:74)
         at 
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:543)
         at 
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:105)
         at 
org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59)
         at 
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89)
         at 
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
         at 
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:717)
         at 
org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
         ... 42 more
Caused by: 
org.apache.openjpa.lib.jdbc.ReportingSQLException: ERROR: 
relation "mappings_layout_chart_mapping_id_seq" does not 
exist {prepstmnt 1646550480 SELECT 
CURRVAL('mappings_layout_chart_mapping_id_SEQ')} [code=0, 
state=42P01]
         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.DBDictionary.executeQuery(DBDictionary.java:4453)
         at 
org.apache.openjpa.jdbc.sql.DBDictionary.getGeneratedKey(DBDictionary.java:4010)
         at 
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:98)
         at 
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:72)
         ... 49 more






-- 
Peter Henderson
Director Starjar Limited.

Mobile: +44 (0) 778 233 8645
Email: peter.henderson@starjar.com
Web: www.starjar.com


Mime
View raw message