You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Marc LaPierre <ml...@rim.com> on 2008/02/14 21:05:37 UTC

@ManyToMany mapping with extra data

Hi all,

I'm trying to do a ManyToMany mapping with additional data in the link
table. Here's a sample: 

@Entity
public class Foo
{
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int fooId;
}

@Entity
public class Bar
{
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int barId;
}

@Entity
public class FooBar
{
	//the primary key is fooId + barId in the database

	@ManyToOne
	@JoinColumn(name="fooId")
	private Foo foo;
	
	@ManyToOne
	@JoinColumn(name="barId")
	private Bar bar;

	private int thisIsFooBared;
}


I've tried several variations of this including adding @Id, but no luck.
I get the following exception: 


---------------------------------------------

org.apache.openjpa.persistence.PersistenceException: Attempt to update
the sequence table "OPENJPA_SEQUENCE_TABLE" failed.  The sequence table
is typically created when you run the mappingtool's refresh action on
any datastore identity class. If you have not run the mappingtool but
want to create the sequence table, run:
java org.apache.openjpa.jdbc.kernel.TableJDBCSeq -action add
	at
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.
java:3849)
	at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:97
)
	at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:75
)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSe
q.java:346)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.ja
va:247)
	at
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java
:60)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStore
Manager.java:549)
	at
org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(Delegati
ngStoreManager.java:134)
	at
org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerIm
pl.java:501)
	at
org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.jav
a:2770)
	at
org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39)
	at
org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.
java:940)
	at
org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1884)
	at
org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1844)
	at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:17
62)
	at
org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime
.java:81)
	at
org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1292)
	at
org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:
861)
	at
org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImp
l.java:408)
	... 23 more
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Invalid
object name 'OPENJPA_SEQUENCE_TABLE'. {prepstmnt 21539046 SELECT
SEQUENCE_VALUE FROM OPENJPA_SEQUENCE_TABLE WHERE ID = ? [params=(int)
0]} [code=208, state=S0002]
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConne
ctionDecorator.java:192)
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$800(Loggin
gConnectionDecorator.java:57)
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection
$LoggingPreparedStatement.executeQuery(LoggingConnectionDecorator.java:8
44)
	at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(Del
egatingPreparedStatement.java:262)
	at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(Del
egatingPreparedStatement.java:252)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.getSequence(TableJDBCSeq.jav
a:442)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.setSequence(TableJDBCSeq.jav
a:483)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSe
q.java:343)
	... 38 more

---------------------------------------------

This table should not be using a sequence or any other kind of generated
ID -- only the 2 foreign keys should act as the identity.

Any thoughts?

Thanks,

Marc

---------------------------------------------------------------------
This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

RE: @ManyToMany mapping with extra data

Posted by Marc LaPierre <ml...@rim.com>.
If anyone else runs into this situation, here is the solution: 


http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_oi
d_entitypk


http://mail-archives.apache.org/mod_mbox/openjpa-users/200707.mbox/%3c11
694049.post@talk.nabble.com%3e


Marc
(always post your solutions!)


-----Original Message-----
From: Marc LaPierre [mailto:mlapierre@rim.com] 
Sent: Thursday, February 14, 2008 3:06 PM
To: users@openjpa.apache.org
Subject: @ManyToMany mapping with extra data

Hi all,

I'm trying to do a ManyToMany mapping with additional data in the link
table. Here's a sample: 

@Entity
public class Foo
{
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int fooId;
}

@Entity
public class Bar
{
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int barId;
}

@Entity
public class FooBar
{
	//the primary key is fooId + barId in the database

	@ManyToOne
	@JoinColumn(name="fooId")
	private Foo foo;
	
	@ManyToOne
	@JoinColumn(name="barId")
	private Bar bar;

	private int thisIsFooBared;
}


I've tried several variations of this including adding @Id, but no luck.
I get the following exception: 


---------------------------------------------

org.apache.openjpa.persistence.PersistenceException: Attempt to update
the sequence table "OPENJPA_SEQUENCE_TABLE" failed.  The sequence table
is typically created when you run the mappingtool's refresh action on
any datastore identity class. If you have not run the mappingtool but
want to create the sequence table, run:
java org.apache.openjpa.jdbc.kernel.TableJDBCSeq -action add
	at
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.
java:3849)
	at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:97
)
	at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:75
)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSe
q.java:346)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.ja
va:247)
	at
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java
:60)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStore
Manager.java:549)
	at
org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(Delegati
ngStoreManager.java:134)
	at
org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerIm
pl.java:501)
	at
org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.jav
a:2770)
	at
org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39)
	at
org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.
java:940)
	at
org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1884)
	at
org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1844)
	at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:17
62)
	at
org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime
.java:81)
	at
org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1292)
	at
org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:
861)
	at
org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImp
l.java:408)
	... 23 more
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Invalid
object name 'OPENJPA_SEQUENCE_TABLE'. {prepstmnt 21539046 SELECT
SEQUENCE_VALUE FROM OPENJPA_SEQUENCE_TABLE WHERE ID = ? [params=(int)
0]} [code=208, state=S0002]
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConne
ctionDecorator.java:192)
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$800(Loggin
gConnectionDecorator.java:57)
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection
$LoggingPreparedStatement.executeQuery(LoggingConnectionDecorator.java:8
44)
	at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(Del
egatingPreparedStatement.java:262)
	at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(Del
egatingPreparedStatement.java:252)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.getSequence(TableJDBCSeq.jav
a:442)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.setSequence(TableJDBCSeq.jav
a:483)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSe
q.java:343)
	... 38 more

---------------------------------------------

This table should not be using a sequence or any other kind of generated
ID -- only the 2 foreign keys should act as the identity.

Any thoughts?

Thanks,

Marc

---------------------------------------------------------------------
This transmission (including any attachments) may contain confidential
information, privileged material (including material protected by the
solicitor-client or other applicable privileges), or constitute
non-public information. Any use of this information by anyone other than
the intended recipient is prohibited. If you have received this
transmission in error, please immediately reply to the sender and delete
this information from your system. Use, dissemination, distribution, or
reproduction of this transmission by unintended recipients is not
authorized and may be unlawful.

---------------------------------------------------------------------
This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.