Many to Many Relations Problem

I have following two classes with many-to-many case:
public class Protocol {
private long protocolId;
private final Collection keyPersons = new ArrayList();
public void addKeyPerson(Person person) {
person.addKeyProtocol(this);
public void removeKeyPerson(Person person) {
person.removeKeyProtocol(this);
public class Person {
private long personId;
private final Collection keyProtocols = new ArrayList();
public void addKeyProtocol(Protocol protocol) {
protocol.getKeyPersonsCollection().add(this);
keyProtocols.add(protocol);
public void removeKeyProtocol(Protocol protocol) {
protocol.getKeyPersonsCollection().remove(this);
keyProtocols.remove(protocol);
The meta data is:
<?xml version="1.0"?>
<jdo>
<package name="peacetech.nih.nhlbi.iasp.dao">
<class name="Protocol" identity-type="application"
objectid-class="peacetech.nih.nhlbi.iasp.dao.oid.ProtocolOid">
<extension vendor-name="tt" key="table" value="protocol"/>
<extension vendor-name="tt" key="pk-column" value="int_protocol"/>
<extension vendor-name="tt" key="lock-column" value="none"/>
<extension vendor-name="tt" key="class-column" value="none"/>
<field name="protocolId" primary-key="true">
<extension vendor-name="tt" key="data-column" value="int_protocol"/>
</field>
<field name="keyPersons">
<collection element-type="Person"/>
<extension vendor-name="tt" key="inverse" value="keyProtocols"/>
<extension vendor-name="tt" key="table" value="KeyPersonnel"/>
<extension vendor-name="tt" key="personId-data-column" value="PID"/>
<extension vendor-name="tt" key="protocolId-ref-column"
value="int_protocol"/>
</field>
</class>
<class name="Person" identity-type="application"
objectid-class="peacetech.nih.nhlbi.iasp.dao.oid.PersonOid">
<extension vendor-name="tt" key="table" value="Personnel"/>
<extension vendor-name="tt" key="pk-column" value="PID"/>
<extension vendor-name="tt" key="lock-column" value="none"/>
<extension vendor-name="tt" key="class-column" value="none"/>
<field name="personId" primary-key="true">
<extension vendor-name="tt" key="data-column" value="PID"/>
</field>-
<field name="keyProtocols">
<collection element-type="Protocol"/>
<extension vendor-name="tt" key="inverse" value="keyPersons"/>
<extension vendor-name="tt" key="table" value="KeyPersonnel"/>
<extension vendor-name="tt" key="protocolId-data-column"
value="int_protocol"/>
<extension vendor-name="tt" key="personId-ref-column" value="PID"/>
</field>
</class>
The assignment works fine beetwen New Persistent Protocol and Persons, but
when ever I try to add new assignment between existing protocol and person:
void updateProtocol(PersistenceManager pm){
Extent e = pm.getExtent (Person.class, true);
Query query = pm.newQuery (Person.class, e, "fname == \"Alex\"");
Collection collection = (Collection) query.execute();
Iterator i = collection.iterator ();
Person alex = (Person)i.next();
System.out.println("Person to assign" + alex);
e = pm.getExtent (Protocol.class, true);
query = pm.newQuery (Protocol.class, e, "projectTitle == \"This is
JDO test N1\"");
collection = (Collection) query.execute();
i = collection.iterator ();
Protocol firstProtocol = (Protocol)i.next();
try {
pm.currentTransaction().begin();
e = pm.getExtent (Person.class, true);
query = pm.newQuery (Person.class, e, "fname == \"Brian\"");
collection = (Collection) query.execute();
i = collection.iterator ();
while (i.hasNext ())
firstProtocol.addKeyPerson((Person)(i.next()));/*Exception
here!*/
pm.currentTransaction().commit();
} catch (Exception ex) {
pm.currentTransaction().rollback();
ex.printStackTrace(System.out);
I have following exception:
javax.jdo.JDOUserException: The given element "
=======Person=======
First Name: Brian
Last Name: Agricola
Phone: null
Email: null
====================" does not meet the requirements for the container.
at
com.solarmetric.kodo.util.SecondClassObjects.checkValue(SecondClassObjects.j
ava:224)
at com.solarmetric.kodo.util.ProxyLinkedList.add(ProxyLinkedList.java:71)
at peacetech.nih.nhlbi.iasp.dao.Person.addKeyProtocol(Person.java:176)
at peacetech.nih.nhlbi.iasp.dao.Protocol.addKeyPerson(Protocol.java:147)
at peacetech.nih.nhlbi.iasp.IASPTest.updateProtocol(IASPTest.java:142)
at peacetech.nih.nhlbi.iasp.IASPTest.updateProtocol(IASPTest.java:110)
at peacetech.nih.nhlbi.iasp.IASPTest.runTest(IASPTest.java:28)
at peacetech.nih.nhlbi.iasp.IASPTest.main(IASPTest.java:22)
I have the same problem also for one to many.
Can you help me with it?
Thanks,
Kirill.

I have following two classes with many-to-many case:
public class Protocol {
private long protocolId;
private final Collection keyPersons = new ArrayList();
public void addKeyPerson(Person person) {
person.addKeyProtocol(this);
public void removeKeyPerson(Person person) {
person.removeKeyProtocol(this);
public class Person {
private long personId;
private final Collection keyProtocols = new ArrayList();
public void addKeyProtocol(Protocol protocol) {
protocol.getKeyPersonsCollection().add(this);
keyProtocols.add(protocol);
public void removeKeyProtocol(Protocol protocol) {
protocol.getKeyPersonsCollection().remove(this);
keyProtocols.remove(protocol);
The meta data is:
<?xml version="1.0"?>
<jdo>
<package name="peacetech.nih.nhlbi.iasp.dao">
<class name="Protocol" identity-type="application"
objectid-class="peacetech.nih.nhlbi.iasp.dao.oid.ProtocolOid">
<extension vendor-name="tt" key="table" value="protocol"/>
<extension vendor-name="tt" key="pk-column" value="int_protocol"/>
<extension vendor-name="tt" key="lock-column" value="none"/>
<extension vendor-name="tt" key="class-column" value="none"/>
<field name="protocolId" primary-key="true">
<extension vendor-name="tt" key="data-column" value="int_protocol"/>
</field>
<field name="keyPersons">
<collection element-type="Person"/>
<extension vendor-name="tt" key="inverse" value="keyProtocols"/>
<extension vendor-name="tt" key="table" value="KeyPersonnel"/>
<extension vendor-name="tt" key="personId-data-column" value="PID"/>
<extension vendor-name="tt" key="protocolId-ref-column"
value="int_protocol"/>
</field>
</class>
<class name="Person" identity-type="application"
objectid-class="peacetech.nih.nhlbi.iasp.dao.oid.PersonOid">
<extension vendor-name="tt" key="table" value="Personnel"/>
<extension vendor-name="tt" key="pk-column" value="PID"/>
<extension vendor-name="tt" key="lock-column" value="none"/>
<extension vendor-name="tt" key="class-column" value="none"/>
<field name="personId" primary-key="true">
<extension vendor-name="tt" key="data-column" value="PID"/>
</field>-
<field name="keyProtocols">
<collection element-type="Protocol"/>
<extension vendor-name="tt" key="inverse" value="keyPersons"/>
<extension vendor-name="tt" key="table" value="KeyPersonnel"/>
<extension vendor-name="tt" key="protocolId-data-column"
value="int_protocol"/>
<extension vendor-name="tt" key="personId-ref-column" value="PID"/>
</field>
</class>
The assignment works fine beetwen New Persistent Protocol and Persons, but
when ever I try to add new assignment between existing protocol and person:
void updateProtocol(PersistenceManager pm){
Extent e = pm.getExtent (Person.class, true);
Query query = pm.newQuery (Person.class, e, "fname == \"Alex\"");
Collection collection = (Collection) query.execute();
Iterator i = collection.iterator ();
Person alex = (Person)i.next();
System.out.println("Person to assign" + alex);
e = pm.getExtent (Protocol.class, true);
query = pm.newQuery (Protocol.class, e, "projectTitle == \"This is
JDO test N1\"");
collection = (Collection) query.execute();
i = collection.iterator ();
Protocol firstProtocol = (Protocol)i.next();
try {
pm.currentTransaction().begin();
e = pm.getExtent (Person.class, true);
query = pm.newQuery (Person.class, e, "fname == \"Brian\"");
collection = (Collection) query.execute();
i = collection.iterator ();
while (i.hasNext ())
firstProtocol.addKeyPerson((Person)(i.next()));/*Exception
here!*/
pm.currentTransaction().commit();
} catch (Exception ex) {
pm.currentTransaction().rollback();
ex.printStackTrace(System.out);
I have following exception:
javax.jdo.JDOUserException: The given element "
=======Person=======
First Name: Brian
Last Name: Agricola
Phone: null
Email: null
====================" does not meet the requirements for the container.
at
com.solarmetric.kodo.util.SecondClassObjects.checkValue(SecondClassObjects.j
ava:224)
at com.solarmetric.kodo.util.ProxyLinkedList.add(ProxyLinkedList.java:71)
at peacetech.nih.nhlbi.iasp.dao.Person.addKeyProtocol(Person.java:176)
at peacetech.nih.nhlbi.iasp.dao.Protocol.addKeyPerson(Protocol.java:147)
at peacetech.nih.nhlbi.iasp.IASPTest.updateProtocol(IASPTest.java:142)
at peacetech.nih.nhlbi.iasp.IASPTest.updateProtocol(IASPTest.java:110)
at peacetech.nih.nhlbi.iasp.IASPTest.runTest(IASPTest.java:28)
at peacetech.nih.nhlbi.iasp.IASPTest.main(IASPTest.java:22)
I have the same problem also for one to many.
Can you help me with it?
Thanks,
Kirill.

Similar Messages

  • Problem in mapping a many to many relation to a list

    Hi,
    I have a problem with mapping a many to many relation to a list.
    I have a Many to Many relation in my database between tables baskets and products. This relation is implemented with a join table basket_products, which has two fields which correspond to the foreign keys to tables baskets and products. The join table need to have another one column "order", which defines the order of the products for the specific basket.
    In my mapping I have:
    @Entity
    @Table(name = "baskets", uniqueConstraints = {})
    public class Components implements java.io.Serializable {
    @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
         @JoinTable( name="baskets_products",
                             joinColumns=@JoinColumn(name="b_id", referencedColumnName="pr_id"),
                             inverseJoinColumns=@JoinColumn(name="pr_id", referencedColumnName="pr_id"))
            //This of course doesn't work!!
           //@OrderBy(value="order")
         public List<Products> getProductses() {
              return this.productses;
         public void setProductses(
                   List<Products> productses) {
              this.productses = productses;
    @Entity
    @Table(name = "products", uniqueConstraints = { })
    public class Products implements java.io.Serializable {
    @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "productses")
         public Set<Baskets> getBasketses() {
              return this.basketses;
         public void setBasketses(Set<Basket> basketses) {
              this.basketses = basketses;
         }In the EJB spec I read that :
    "The property or field name must correspond to that of a persistent property or field of the associated
    class."
    What to do if I want to use a field from the join table to do the ordering of the list??
    My problem is that the field "order", is not defined to the EJB container as a persistent field, so it cannot be used. But for my needs it is necessary that this field is included in the join table.
    I thought that I could use the secondary table annotation to map the join table to the Baskets class, as well, so that I can define the order field, but this solution seems to me as a really wrong one.
    Can anyone help me??
    Thanks,
    Elenh.

    Hi Martin-
    Can you please help me. Here are the details:
    We have created an AQ in Oracle DB which will have the following message Structure:
    CREATE OR REPLACE TYPE enqueue_payload AS OBJECT
    ( field1 VARCHAR2(100),
    field2 VARCHAR2(100),
    field3 DATE,
    field4 VARCHAR2(100),
    field5 NUMBER,
    payload CLOB,
    In the Payload field we are enqueing an XML message.
    We have to use a OSB proxy service to dequeue the message from the AQ, transform it to another format and send to a SOA Composite.
    We created a AQ Adapter in Jdeveloper 11g and imported the WSDL, XSD and .jca jca binding file into the OSB project. And configured the OSB proxy service using the WSDL imported.
    However in OSB proxy service message flow when I try to create an XQUERY transformation, I see that the Payload field does not expose the structure of the XML message that is being enqueued. I even changed the message structure definition to have the payload field as XMLType. But it didn't help.
    On analyzing the XSD created by AQ Adapter, I see that the payload is being defined as "string" in the XSD.
    Inputs Needed
    =========
    1. How can we parse the payload field defined as CLOB/XMLType in OSB so that I can see the structure of the XML message it holds ?
    2. Is there any in-built function in OSB to convert it to XML ?
    3. Any other inputs in order to transform the XML message coming in the payload field as CLOB/XMLType
    Please provide your inputs and I hope that I have clearly explained my use case.
    Thanks in advance for your time and help!!
    Regards,
    Dibya

  • Many to Many relation problem

    Hi,
    JDeveloper 11.1.1.6
    3 tables, let's name them A, B and RelAB
    By default, there is a [1 to *] from A to RelAB and a [1 to *] from B to RelAB.
    Since I wanted to use a master-detail view on my web page, I didn't have the choice to modify these Associations and Links to a [* to *] from A to B, and as well from B to A.
    Now you test the whole thing by running the AppModule. Everything works like a charm.
    The problem is if I go into my A view object and then I change the SQL Mode from Normal to Expert inside the Query tab, the minute I run my AppModule, one of my many to many relationship breaks. Notice that I did not change anything else, just switch from Normal to Expert. Let's say that the A to B relation is working but not the B to A.
    If I put it back to Normal, it works again. You might want to ask, why bother with Expert Mode? It is just that I want to modify this query, I was just trying to identify the source of the problem.
    Anybody experience a similar problem with many-to-many relationships?

    I assume your question is on JAXB, correct?
    I think you need to make on side of the relationship transient, or remove it.
    James : http://www.eclipselink.org

  • A many-to-many relational problem (SQL and CFM)

    My question:
    How to get CFM to return a many-to-many relationship in one
    row using cfloop
    My table structure:
    Table A - Books
    BookID | BookName
    1 | Book One
    Table B -
    RelatingTable
    BookID | AuthorID
    1 | 60
    1 | 61
    Table C - Authors
    AuthorID | AuthorName
    60 | Bob
    61 | Joe
    My query:
    SELECT * FROM Books, RelatingTable, Authors AS a
    INNER JOIN Books AS b ON b.BookID = r.BookID
    INNER JOIN RelatedTable AS r ON r.AuthorID = a.AuthorID
    Output I am getting:
    b.BookID | b.BookName | r.BookID | r.AuthorID | a.AuthorID |
    a.AuthorName
    ---------|------------|----------|------------|------------|-------------
    1 | Book One | 1 | 60 | 60 | Bob
    1 | Book One | 1 | 61 | 61 | Joe
    I am using a UDF that turns my relationship into a comma list
    (authorlist), but the duplicates still return in CFM because the
    JOIN relationship
    The code I am using in CFM:
    <cfloop query="rsBooksQuery">
    #b.BookName#, written by #authorlist#
    </cfloop>
    How Coldfusion is displaying my output:
    Book One, written by Bob, Joe
    Book One, written by Bob, Joe
    How I want my output displayed:
    Book One, written by Bob, Joe
    I need this to work in cfloop and not cfoutput! I know that
    you can use group in CF output, but for the conditions I am using
    this query, it must be in a loop
    the reason why i keep the JOINs even though i have a UDF to
    create a comma list is that some of my CFM pages use variables
    passed to the qry to limit which books are displayed, for example
    &author=60 (which would display a list of Bob's books that
    include the comma list)
    If you can suggest anything to help me I will be very
    thankful

    I need this to work in cfloop and not cfoutput! I know that
    you can use
    group in CF output, but for the conditions I am using this
    query, it
    must be in a loop
    If you can suggest anything to help me I will be very
    thankful
    If you can not use <cfoutput...> with its group
    feature, you need to
    recreate the functionality with <cfloop...>. You can
    create nested
    <cfloop...> tags that keep track of the changing group
    value. It takes
    more code, but that's what happens when one sets outside the
    bounds of
    the built in functionality.

  • Many-to-many relation

    Hi,
    There is a many-to-many relation defined for the following tables:
    Table T_PRICEAFFECTOR
    Name Type
    NAME VARCHAR2(100)
    ISACCUMULATIVE NUMBER(1)
    RATE NUMBER(10,10)
    PRICEAFFECTOR_ID NOT NULL NUMBER(10)
    CATALOG_ID NOT NULL NUMBER(10)
    UNITTYPE NOT NULL NUMBER(1)
    and
    Table T_PRICEAFFECTINGCHAIN
    Name Type
    PRICEAFFECTINGCHAIN_ID NOT NULL NUMBER(10)
    NAME VARCHAR2(100)
    ISDEFAULTFORSTORE NUMBER(1)
    CATALOG_ID NOT NULL NUMBER(10)
    There is also a third table defining the many-to-many relation:
    TABLE T_PRICEAFFECTORTOCHAIN
    Name Type
    PRICEAFFECTOR_ID NOT NULL NUMBER(10)
    PRICEAFFECTINGCHAIN_ID NOT NULL NUMBER(10).
    The classes defined are as follows:
    public class PriceAffectorsChain
         private Catalog catalog;
         private long priceAffectorsChainId;
         private String name;
         private boolean isDefaultForStore;
         private Collection priceAffectors = new HashSet ();
         private Collection products = new HashSet ();
    public class PriceAffector
         private long priceAffectorId;
         private long isAccumulative;
         private String name;
         private double rate;
         private Catalog catalog;
         private int unitType;
         private Collection priceAffectorsChains = new HashSet ();
    and these are defined in the jdo descriptor in the following way:
    <class name="PriceAffector" identity-type="application"
    objectid-class="jp.telewave.platpark.eis.dao.pk.PriceAffectorPK">
         <extension vendor-name="kodo" key="lock-column" value="none"/>
         <extension vendor-name="kodo" key="class-column" value="none"/>
         <extension vendor-name="kodo" key="table" value="T_PRICEAFFECTOR"/>
         <field name="priceAffectorId" primary-key="true">
              <extension vendor-name="kodo" key="data-column"
    value="PRICEAFFECTOR_ID"/>
         </field>
         <field name="isAccumulative">
              <extension vendor-name="kodo" key="data-column" value="ISACCUMULATIVE"/>
         </field>
         <field name="name">
              <extension vendor-name="kodo" key="data-column" value="NAME"/>
         </field>
         <field name="rate">
              <extension vendor-name="kodo" key="data-column" value="RATE"/>
         </field>
         <field name="unitType">
              <extension vendor-name="kodo" key="data-column" value="UNITTYPE"/>
         </field>
         <field name="catalog">
              <extension vendor-name="kodo" key="catalogId-data-column"
    value="CATALOG_ID"/>
         </field>
         <field name="priceAffectorsChains">
              <collection element-type="PriceAffectorsChain"/>
              <extension vendor-name="kodo" key="read-only" value="true"/>
              <extension vendor-name="kodo" key="inverse" value="priceAffectors"/>
              <extension vendor-name="kodo" key="table"
    value="T_PRICEAFFECTORTOCHAIN"/>
              <extension vendor-name="kodo" key="priceAffectorId-ref-column"
    value="PRICEAFFECTOR_ID"/>
              <extension vendor-name="kodo" key="priceAffectorsChainId-data-column"
    value="PRICEAFFECTINGCHAIN_ID"/>
         </field>
    </class>
    <class name="PriceAffectorsChain" identity-type="application"
    objectid-class="jp.telewave.platpark.eis.dao.pk.PriceAffectorsChainPK">
         <extension vendor-name="kodo" key="lock-column" value="none"/>
         <extension vendor-name="kodo" key="class-column" value="none"/>
         <extension vendor-name="kodo" key="table" value="T_PRICEAFFECTINGCHAIN"/>
         <field name="priceAffectorsChainId" primary-key="true">
              <extension vendor-name="kodo" key="data-column"
    value="PRICEAFFECTINGCHAIN_ID"/>
         </field>
    <field name="catalog">
              <extension vendor-name="kodo" key="catalogId-data-column"
    value="CATALOG_ID"/>
         </field>
         <field name="name">
              <extension vendor-name="kodo" key="data-column" value="NAME"/>
         </field>
         <field name="isDefaultForStore">
         <extension vendor-name="kodo" key="data-column"
    value="ISDEFAULTFORSTORE"/>
         </field>
         <field name="priceAffectors">
              <collection element-type="PriceAffector"/>
              <extension vendor-name="kodo" key="read-only" value="false"/>
              <extension vendor-name="kodo" key="inverse"
    value="priceAffectorsChains"/>
              <extension vendor-name="kodo" key="table"
    value="T_PRICEAFFECTORTOCHAIN"/>
              <extension vendor-name="kodo" key="priceAffectorsChainId-ref-column"
    value="PRICEAFFECTINGCHAIN_ID"/>
              <extension vendor-name="kodo" key="priceAffectorId-data-column"
    value="PRICEAFFECTOR_ID"/>
         </field>
         <field name="products">
         <collection element-type="Product"/>
         <extension vendor-name="kodo" key="inverse" value="priceAffectorsChain"/>
         </field>
    </class>
    =============================================================
    Ok. The problem with the mapping is that it works only one way. What I
    mean is that when I try to add new PriceAffectorsChain with many
    PriceAffector objects only the PriceAffectorsChain object is being
    persisted, and none of the PriceAffectors are persisted in the
    many-to-many table (T_PRICEAFFECTORTOCHAIN), even when the read-only
    extensions are set.
    That was not the case when I tried to add new PriceAffector with many
    PriceAfffectorsChain - everything worked.
    Any Ideas?
    -Ivan

    Abe White wrote:
    When you have a two-sided relation, you need to be maintaining both sides
    of the relation at all times. Whenever an A is added to a B, the B must
    be added to the A as well. Keep your in-memory Java objects consistent
    (just as if they were not persistent), and JDO will take care of the rest.Abe White wrote:
    When you have a two-sided relation, you need to be maintaining both sides
    of the relation at all times.
    Whenever an A is added to a B, the B must
    be added to the A as well. Keep your in-memory Java objects consistent
    (just as if they were not persistent), and JDO will take care of the rest.Ok. I agree.
    I think that I'm doing this or maybe I'm wrong. Below is the code that
    adds new price affectors chain with collection of price affectors (all of
    them already persistent). Each of the price affectors is being looked up
    and is consistent (this is what getObjectById is doing, isn't it?) and
    then the price affector chain is being persisted.
    =================================================================
    PersistenceManager pm = null;
    PriceAffectingChain newPriceAffectorsChain = null;
    HashSet priceAffectors = null;
    try {
    pm = persistenceManagerFactory.getPersistenceManager();
    // getting the catalog object
    long catalogId = priceAffectorsChain.getCatalog().getCatalogId();
    CatalogPK catalogPK = new CatalogPK(catalogId);
    Catalog newPriceAffectorsChainCatalog =
    (Catalog)pm.getObjectById(catalogPK, true);
    // making new price affecting chain
    newPriceAffectorsChain = new PriceAffectingChain(
    BeanHelper.getNextSequence(DBObjects.SEQ_PRICEAFFECTINGCHAIN),
    priceAffectorsChain.getName(),
         priceAffectorsChain.getIsDefaultForStore(),
         newPriceAffectorsChainCatalog);
    // retrieval of price affector objects for this chain
    System.out.println("the size of the price affectors is: " +
    priceAffectorPKs.length);
    if (priceAffectorPKs != null && priceAffectorPKs.length > 0) {
         priceAffectors = new HashSet(priceAffectorPKs.length);
    for (int i = 0; i < priceAffectorPKs.length; i++) {
              PriceAffectorPK currentPAPK = priceAffectorPKs;
              PriceAffector currentPA = (PriceAffector)pm.getObjectById(currentPAPK,
    true);
              priceAffectors.add(currentPA);
              System.out.println("The " + currentPA.getName() + " price affector was
    added");
    if (priceAffectors == null) {
         priceAffectors = new HashSet();
    System.out.println("size of priceAffectors: " +
    priceAffectors.size());
    newPriceAffectorsChain.setPriceAffectors(priceAffectors);
    pm.makePersistent(newPriceAffectorsChain);
    } catch {
    ===========================================================
    The problem is that the presistence works only for the table of
    PriceAffectingChain obejct and not for the relation table. I tried on
    purpose to add new price affectors with collection of price affecting
    chains and it worked for both tables (the one for PriceAffector object and
    the relation table.
    I have no idea what I can try next. Any advice or help are welcomed.
    Thanks.
    -Ivan

  • Many to many relationship problem

    Hi folks!
    I am having the following problem when mapping many-to-many relationships: "More than one writable many-to-many mapping cannot use the same relation table".
    This is what I am doing: I have a class Person and a class Meeting. One Person has many meetings and one Meeting has many participants (person).
    I did the M-to-M relationship for the class Person and it worked fine in the workbench. But when I tried to do it in the Meeting class the workbench complained with that error.
    I believe it might be a problem with the source and target references but I couldn't figure out how to solve it.
    If I check in the intermediate table there are only 2 references created.
    Can anyone help?

    Hello,
    Firstly, think about object model consistency (without TopLink or other persistence layer at all): should you be changing one side (eg Person), adding a meeting, without changing the other side? Is that object model self-consistent? It doesn't appear so to me- I can navigate from meeting to person and not get the same results as navigating from person to meeting. All this is irrespective of the persistence layer.
    TopLink, first and foremost, expects that your object model is self-consistent. If it is, then you will find that the problem you indicate is no longer a problem- if i update a person with a new meeting, i change the meeting to person relationship as well. This means that although one direction is read-only to TopLink, the other is not- so the data will be written.
    I hope this helps,
    Christian

  • Hibernate - Spring - problem with mapping (many-to-many)

    Hello,
    I want to map the following situation. I have a table called EDUCATION and a table called SCHOOLS. Between those tables I have an associative table called EDUCATION_SCHOOLS. The (usefull) fields:
    EDUCATION:
    id (long) - PK
    name (varchar)
    versionNr (long)
    SCHOOLS:
    id (long) - PK
    name (varchar)
    versionNr (long)
    EDUCATION_SCHOOLS:
    id (long) - PK
    education_id (long) (FK to EDUCATION.id)
    school_id (long) (FK to SCHOOLS.id)
    name (varchar)
    versionNr (long)
    Their is a Unique Constraint between EDUCATION_SCHOOLS.education_id and EDUCATION_SCHOOLS.school_id.
    What I want to be able to do:
    EDUCATION: select, update, insert
    SCHOOLS: select, update, insert
    EDUCATION_SCHOOLS: select, update (only the non-FK fields), insert
    I never want to delete anything in those tables. (and it's never ever going to be an option either)
    Hibernate version:
    Hibernate-Version: 3.0.5
    Mapping documents:
    Education:
    <hibernate-mapping>
         <class name="##.Education" table="EDUCATION">
              <id name="id" column="ID" type="java.lang.Long">
                   <generator class="sequence">
                        <param name="sequence">EDUCATION_SEQ</param>
                   </generator>
              </id>
              <version name="versionNr" column="VERSIONNR" type="long"/>
              <property name="name" column="NAME" type="string" />
            <set name="SCHOOLS" table="EDUCATION_SCHOOLS">
                <key column="EDUCATION_ID" />
                <many-to-many class="##.Schools" column="SCHOOL_ID" lazy="false" />
            </set>
    </hibernate-mapping>
    Schools:
    <hibernate-mapping>
         <class name="##.Schools" table="SCHOOLS">
              <id name="id" column="ID" type="java.lang.Long">
                   <generator class="sequence">
                        <param name="sequence">SCHOOLS_SEQ</param>
                   </generator>
              </id>
              <version name="versionNr" column="VERSIONNR" type="long"/>
              <property name="name" column="NAAM_NAME" type="string" />
            <set name="educations" table="EDUCATION_SCHOOLS" inverse="true" cascade="none">
                <key column="SCHOOL_ID" />
                <many-to-many class="##.Schools" column="SCHOOL_ID" lazy="proxy"/>
            </set>
    </hibernate-mapping>
    Education_schools:
    <hibernate-mapping>
    <class name="##.EducationSchools" table="EDUCATION_SCHOOLS">
               <id name="id" column="ID" type="java.lang.Long" unsaved-value="0">
                   <generator class="sequence">
                        <param name="sequence">SEQ_EDUCATION_SCHOOLS</param>
                   </generator>
              </id>
              <version name="versionNr" column="VERSIONNR" type="long" />
              <many-to-one name="education" class="##.Education" cascade="none" lazy="proxy"
                           column="EDUCATION_ID" not-null="true"/>
            <many-to-one name="schools" class="##.Schools" cascade="none" lazy="proxy"
                        column="SCHOOL_ID" not-null="true"/>  
    </hibernate-mapping>   
    Name and version of the database you are using:
    Oracle XE 10g
    I am able to:
    EDUCATION: select, insert, update
    SCHOOLS: select, insert, update
    EDUCATION_SCHOOLS: select
    Problems:
    EDUCATION_SCHOOLS: when I try to insert, I sometimes get unique constraint violations. (when I should get them, thus I'm trying to insert something that already exists .. but how do I stop Hibernate from Inserting?)
    EDUCATION_SCHOOLS: when I try to update, sometimes it works, but often I get:
    23:03:55,484 [http-8081-1] ERROR be.vlaanderen.lne.vea.epb.ui.struts.EpbExceptionHandler - org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [##.EducationSchools] with identifier [null]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [##.EducationSchools#<null>]
    ex.getMessage() Object of class [##.EducationSchools] with identifier [null]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [##.EducationSchools#<null>]
    org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [##.EducationSchools] with identifier [null]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [##.EducationSchools#<null>]
    Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect):As you can see from the stacktrace I use Spring for the transactionManager: org.springframework.orm.hibernate3.HibernateTransactionManager in which I use e sessionFactory: org.springframework.orm.hibernate3.LocalSessionFactoryBean
    In my DAO, I try to save with the regular this.getHibernateTemplate().saveOrUpdate that has always worked for me.
    Another problem I have:
    when i update "name" in EDUCATION, the records with that ID are delete from EDUCATION_SCHOOLS ...
    As I am experiencing 3 different problems, I'm pretty sure something is wrong in the mapping files .. however I fail to find out what .. Any input would be greatly appreciated.
    (I translated some class/table-names, that's what the ## cause)
    Edited by: Bart_Blommaerts on Jul 29, 2008 11:53 PM

    Thank you for your input.
    When I try what you suggest, I still get the same error:
    16:39:30,406 [http-8081-1] ERROR ###.EpbExceptionHandler - org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [###.EducationSchools] with identifier [2]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]
    ex.getMessage() Object of class [###.EducationSchools] with identifier [2]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]
    org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [###.EducationSchools] with identifier [2]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]
    Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]If you had to map the database tables, I'm trying to map, how would you do it?

  • Many-to-Many relation sample in ADF

    I have a requirement to implement a screen
    Three tables 1) Users 2) Access 3) Documents
    The Access table contains both the references DocId and UserId and acts as the intersection table.
    Users table is related to Documents through the Access table which acts as the intersection table and vice versa. I need to create a screen gui which will show all the documents a user has. Secondly also show all the users who has permission to a particular document. Is there any sample adf application which implements a simple many-to-many relation.
    I am planning to create three entity objects - UsersEO, AccessEO, DocumentsEO
    two view objects - UsersVO and DocumentsVO
    one view link -UsersDocumentVL
    Also which GUI components is best suited to address this. How many Entity Objects, View Objects and View Link should I create. Any simple sampe will help.
    Regards
    Thomas

    Thomas,
    There are of course many ways to implement your requirement. Try this exercise... forget about ADF for a moment; put your computer away (well, finish reading this first ;) ). Grab a pencil and paper.. assuming you could do anything, how would you like the screen to work? Draw it out on a piece of paper and describe how it works. You've just created a rudimentary specification. Now, come back to this thread and describe your specification - perhaps then we can help you implement your spec using ADF (or at least tell you "not possible" and describe why).
    Best,
    John

  • I''m new to Mac, how do I install Adobe CD? I put it in the CD drive and get a menu, everything I click on goes nowhere. In Microsoft, I installed many programs with no problem

    I''m new to Mac, how do I install Adobe CD? I put it in the CD drive and get a menu, everything I click on goes nowhere. In Microsoft, I installed many programs with no problem

    Is the Adobe CD a MAC app ?
    If it is a program for Windows you will not be able to install it.
    If you nedd that program you can either buy the equivalent for Mac or install a way to run Windows under Mac (may be a cheaper solution)

  • Can't open iTunes, it said it has failed to start because MSVCR80.dll was not found, and I re-installed application many times and still problem persist, how do I solve this?

    can't open iTunes, it said it has failed to start because MSVCR80.dll was not found, and I re-installed application many times and still problem persist, how do I solve this?

    Try the following user tip:
    Troubleshooting issues with iTunes for Windows updates

  • Problem in Many-to-Many Associations (JBO-27014 error)

    I am facing a problem during insertion in an Intersection table.
    I have 3 tables Customer, Accounts and Customer_Account. In order to implement the Many to Many relationship between Customer and Accounts, I created an intersection table Customer_Account.
    Table Structure
    CUSTOMER
    Cust_id NUMBER NOT NULL PK
    Name VARCHAR2(50) NOT NULL
    ACCOUNT
    Account_Id NUMBER NOT NULL PK,
    Account_number NOT NULL,
    Sort_Code NUMBER NOT NULL,
    Account_Type VARCHAR2(10) NOT NULL
    CUSTOMER_ACCOUNT
    Cust_Id NUMBER NOT NULL,
    Account_Id NUMBER NOT NULL
    I created an Association CustAcctAsso between Customer and Account with Customer_Account as intersection entity. Then created a viewlink CustAcctViewLink with CustomerView as Source entity, AccountView as Destination entity and selected the CustAcctAsso as association.
    I included this in the application module using the following steps
    Selected AccountView via CustAcctViewLink in the Available view pane and selected CustomerView in Data model pane. Clicked > to add AccountView via CustAcctViewLink as a restricted view.
    Also added CustomerView via CustAcctViewLink as a restricted view.
    When I tried to insert data through the second restricted view I am getting an JBO 27014 Attribute Sort Code in Account is required.
    It would be very helpful if someone gives me a solution quickly.
    Thanks
    Renuka

    Thanks, now I am able to insert data into CUSTOMER and ACCOUNT table, but not in the intersection table.
    It seems that we cannot do any insertion into the intersection table. Please advice me, this is urgent.OK here's what you need to do to insert a new row in both ACCOUNT and INTERSECTION tables.
    1. Create a new viewobject with a join of INTERSECTION and ACCOUNT tables such that both are updateable but ACCOUNT is reference entity.
    -- This is assuming you want to insert a new account when you insert a new account id in the intersection table otherwise, you can make ACCOUNT entity readonly as well.
    2. Create a viewlink between Customer viewobject and this NewViewObject (1-* ViewLink).
    3. If the assumption in step 1 is NOT to update/insert new Accounts form this VO, then you're done. Add the new viewobject usage in your application module and you should be able to use it to edit/insert intersection details.
    Otherwise -
    Set the Updateable flag on AccountID (from the Account entity usage in the NewViewObject) to "never" udpateable.
    Set the Updateable flag on Other attributes from the Account entity usage in the NewViewObject to udpateable-while-new or always as desired.
    4. Select to generate EntityDefImpl subclass for Account table and override the protected method createInstance as below:
      protected EntityImpl createInstance(DBTransaction txn, AttributeList al)
        // TODO:  Override this oracle.jbo.server.EntityDefImpl method
        return super.createInstance(txn, al);
      }5. Select to generate a ViewRowImpl subclass with accessors for this NewViewObject
    6. Add the following logic in setAccountID() method (assuming AccountId attribute is editable and from Intersection entity)
    (Note you'll also have anothe attribute AccountId1 from Account entity which should be readonly as marked in step 3.)
    //get the current intersection entity.
    IntersectionImpl intersection = (IntersectionImpl)getEntity(1);
    setAttributeInternal(ACCOUNTID1, value);
    //if it is same as I added and is not the same as new one
    //framework may assign a new intersection entity based on FK.
    IntersectionImpl newIntersection = (IntersectionImpl)getEntity(1);
    IntersectionDefImpl intersectiondef = (IntersectionDefImpl)IntersectionImpl.getDefinitionObject();
    IntersectionEnrollmentImpl myVO = ((IntersectionEnrollmentImpl)getViewObject());
    DBTransaction dbtxn = myVO.getDBTransaction();
    //see if a intersection exists with this FK
    intersection = (IntersectionImpl)intersectiondef.findByPrimaryKey(dbtxn, IntersectionImpl.createPrimaryKey(value));
    //if this viewrow created a new intersection earlier which is different from
    //the current intersection entity, remove the old one as I created it.
    if ((intersectionAdded != null) && (intersection != intersectionAdded || newIntersection != intersectionAdded))
      if (intersection == null)
        //if I added this intersection as new, reuse-it.
        intersection = intersectionAdded;
        intersection.setIntersectionid(value);
      else
        //if I added this intersection as new, remove it.
        System.out.println(">>>>removing :"+intersectionAdded.getAttribute(0));
        intersectionAdded.remove();
        intersectionAdded = null;
    if (intersection == null)
      //if new intersection is null = no intersection exists with this key, then create a new one.
      intersection = (IntersectionImpl)intersectiondef.createInstance(dbtxn, new AttributeListImpl());
      intersection.setIntersectionid(value);
      intersectionAdded = intersection;
      setEntity(1, intersection);
      myVO.notifyRowUpdated(findRowSetForRow(this), new ViewRowImpl[]{this}, new int[]{2,3});
    else if (intersection != newIntersection)
      //otherwise, create a set the new intersection entity as my intersection entity reference
      setEntity(1, intersection);
      myVO.notifyRowUpdated(findRowSetForRow(this), new ViewRowImpl[]{this}, new int[]{2,3});
    }Now when you insert a new row in this NewViewObject, you can either enter a new Account or refer to an existing Account.
    The setAccountId() method will automatically bring the Account details for existing accounts or create a new Account entity as in the above logic.

  • Additional properties on Many-to-Many relation

    Hi,
    I've trawled through the archive and can't see if this is answered (nor can I find it in the documentation) so apologies if I've missed something obvious.
    I have a logical model with several many-to-many relationships. Clearly I can (and probably should) resolve them, but for a number of reasons I'd prefer, for now, to leave them as m:n.
    On at least one of the m:n I want to add additional (non-FK attributes) to the relationship. There is even a section of the Relation Properties dialog that looks like it should allow me to do so (Attributes) but this is only populated in a 1:m relationship.
    Is there any way of directly adding the non-FK attributes to the relationship? Or do I have to resolve the m:n and add the attributes to the new entity? Or is there some way in the transformation of adding the attributes?
    Thanks
    Ian

    Hi Ian,
    I want to add additional (non-FK attributes) to the relationshipIt's not possible in current release.
    It's better to resolve the relationship to entity and to add attributes there.
    Philip

  • Valueholderinterface - Many-to-Many mapping problem

    Hi
    i have two tables users and teams and i have created many-to-many relationship between two table through intermediated(users_teams) table. Here user can have many teams and team can have many users.But the following exception i m getting while getting teams from user and users from team.
    Caused by: Exception [TOPLINK-0] (OracleAS TopLink - 10g (9.0.4.2) (Build 040311
    )): oracle.toplink.exceptions.IntegrityException
    Descriptor Exceptions:
    Exception [TOPLINK-2] (OracleAS TopLink - 10g (9.0.4.2) (Build 040311)): oracle.
    toplink.exceptions.DescriptorException
    Exception Description: The attribute [teams] is declared as type ValueHolderIn
    terface, but its mapping does not use indirection.
    Mapping: oracle.toplink.mappings.ManyToManyMapping[teams]
    Descriptor: Descriptor(com.test.Users --> [DatabaseTable(USERS)])
    Exception [TOPLINK-7] (OracleAS TopLink - 10g (9.0.4.2) (Build 040311)): oracle.
    toplink.exceptions.DescriptorException
    Exception Description: The attribute [teams] should be of type Vector (or a ty
    pe that implements Map or Collection, if using Java 2).
    Mapping: oracle.toplink.mappings.ManyToManyMapping[teams]
    Descriptor: Descriptor(com.test.Users --> [DatabaseTable(USERS)])
    Exception [TOPLINK-2] (OracleAS TopLink - 10g (9.0.4.2) (Build 040311)): oracle.
    toplink.exceptions.DescriptorException
    Exception Description: The attribute [users] is declared as type ValueHolderIn
    terface, but its mapping does not use indirection.
    Mapping: oracle.toplink.mappings.ManyToManyMapping[users]
    Descriptor: Descriptor(com.test.Teams --> [DatabaseTable(TEAMS)])
    Exception [TOPLINK-7] (OracleAS TopLink - 10g (9.0.4.2) (Build 040311)): oracle.
    toplink.exceptions.DescriptorException
    Exception Description: The attribute [users] should be of type Vector (or a ty
    pe that implements Map or Collection, if using Java 2).
    Mapping: oracle.toplink.mappings.ManyToManyMapping[users]
    Descriptor: Descriptor(com.test.Teams --> [DatabaseTable(TEAMS)])
    Exception [TOPLINK-163] (OracleAS TopLink - 10g (9.0.4.2) (Build 040311)): oracl
    e.toplink.exceptions.DescriptorException
    Exception Description: This mapping's attribute class does not match the collect
    ion class. [class java.util.Vector] cannot be assigned to [interface oracle.top
    link.indirection.ValueHolderInterface].
    Please help me out to resolve this problem.

    Either use indirection in your mappings, or change you class to just use a normal collection, not a ValueHolderInterface.
    -- James : http://www.eclipselink.org

  • HT1926 i've tried so many times but the problem still exists! please help!!

    i've tried so many times but the problem still exists! please help!!

    Could you describe what your problem is, please?

  • I have been using my .mac email address for many years without a problem.  Suddenly over the last few days the emails have been coming in sporadically.  I know this becasue all the emails are coming in on my phone and on the laptop, not on iMac.

    I have been using my .mac email address for many years without any problem.  Suddenly the emails are coming in sporadically or not at all.  I know this because they are all coming in on my phone and laptop.  My gmail account seems unaffected with emails coming in fine.   Any ideas?  Thanks
    Marian

    Back up all data. Rebuild the mailbox.

Maybe you are looking for

  • CWMS Permissions and Email Updates

    We are on our 2nd month of running CWMS and so far we are very happy with the product. Couple of questions have popped up so far: 1) Host or Administrator. Will it be possible in the future to delegate a "help Desk" type role to allow a user to have

  • Logical data base

    hi experts!! i am working on the LDb  report and i have created a LDB zaxxx in se36 and using the same LDB to code in se38 and in attributes i have mentioned the name of LDB. when i code follwoing: GET ZAXXXX  FIELDS INVOICE_NUM CUST_NAME CUST_PO_NUM

  • Best practices Struts for tech. proj. leads

    baseBeans engineering won best training by readers of JDJ and published the first book on Struts called FastTrack to Struts. Upcoming class is live in NYC, on 5/2 from 7:30 AM to 1:00PM. We will cover db driven web site development, process, validati

  • SXI_CACHE vs. RWB Cache Monitoring

    I'm familiar with the functionalities of transaction SXI_CACHE, as I've used it on a previous project. However, I have not used the Cache Monitoring function in the RWB, and was curious what the differences were. When would you prefer to use one over

  • Send Email with Webdynpro for Abap

    Hi, i want to send an email without a attachment after the customer has filled a form. The Webdynpro for Abap action must send a notification Email to the service department about these new request. Has anyone an example how to send an email with Web