One to Many Report Problem
I have an Item table and an Orders table linked for which I want to select certain Items and related Orders. The tables are linked via an Item No field. I want to select all items for which the total of (QOH + QOO - Reqmts) is negative. There can be multiple Orders for each item, or there can be no Orders for an item. The Items I want listed are those in the negative as stated above.
I have a formula which calculates Availability (QOH + open orders - requirements). QOH and requirements are straightforward and in the Items table. The open orders are a Running Total field for orders that are open and for which there is still a balance due.
My problem is that my report only lists those Items that have Orders associated with them. I also need Items that have no orders associated with them. When I tinker with the join type and the enforcement I get way too much data returned.
Are there any suggestions on how I can get the desired result?
Thanks.
OK, I think I understand.
The problem you're facing here is that as soon as you use a field from the MOS table, you'll lose all the IM records which have no orders, because the MOS fields are all null for those records. Unless you 'protect' them, which is what I'm trying to explain.
The best place for you to start is with a simple query which doesn't include any fields from the MOS table, like {IM.IM_PROD_CODE} in "020" to "073". Try this without any MOS fields displayed in the report initially, and then add a couple. I don't think this will knock out your nulls, but it might. No formulas, just fields.
Now add the second line
and {MOS.MOS_STATUS} <= 1.00
This will knock out the nulls because you're accessing the MOS table in an unprotected way. The reason is that as soon as you use a null value in a formula, the record is automatically rejected.
But if you change your formula to something like this:
{IM.IM_PROD_CODE} in "020" to "073"
and ( isnull({MOS-IM-KEY})
or ( not isnull({MOS-IM-KEY} and {MOS.MOS_STATUS} <= 1.00 ) )
you should find that the null records stay.
Now if you've got another formula which accesses the MOS table, you need to cater for the nulls there too. For example, if you need to access the quantity of the item (lets say it's called Qty), you might need to do the following:
local numbervar Qty := if isnull({MOS.QTY} then 0 else {MOS.QTY};
and so on.
But because you're new to this you need to build it up slowly, watching that your null records don't disappear.
Andrew
Similar Messages
-
Hi,
I am haviing a crystal report problem. The problem relates to a one-to-many relationship involving two tables.
I have a similar setup to the following:
I have 2 database tables: table1 & table2
table1 consists of 3 fields:
{id#}, {yes/no},{up/down}
table2 consists of 2 fields:
{id#},
the field can contain any of the following values: 'open', 'closed', 'final', 'complete'.
The problem is that there exist many states to one id#.
I have a bar graph in my report that displays a bar for the count of the{yes/no} field and a bar for the count of the {up/down} field. I want also a bar for the count of when the field = 'final'.
What happens when I write a formula for the field in the second table and place it in the 'show values' section of the chart expert, is the count displayed in each bar on the graph increases significantly. I am assuming this is because there are multiple records in table 2 for each record in table 1.
What I want to happen is that the graph displays bar 1 and bar 2 correctly and then when I put in the formula for the third bar, it simply displays that bar with the count for when the field = 'final'. I dont want it to affect the whole garph.
Has anyone got any suggestions on how I can do this?
I have tried messing around with the distinct records setting in crystal and also by writing an sql query specifying DISTINCT keyword instead of using the select expert, but to no avail.
Please please can someone help me with this issue.
Thank you.
JYou can add a 1-1 query key through the code API in a descriptor amendment method. You could also define a selection criteria on the 1-m mapping to filter the type=2.
Example: (see Foundation Library manual 8-17)
OneToOneQueryKey queryKey = new OneToOneQueryKey();
queryKey.setName("organization");
queryKey.setReferenceClass(Organization.class);
ExpressionBuilder builder = new ExpressionBuilder();
queryKey.setJoinCriteria(builder.getField("ORGANIZATION.ORG_ID").equal(builder.getParameter("RELATIONSHIP.PARENT_ID").and(builder.getParamater("RELATIONSHIP.RELATIONSHIP_TYPE").equal(2)));
relationDescriptor.addQueryKey(queryKey);
Example: (of 1-m mapping with selection criteria)
OneToManyMapping mapping = new OneToManyMapping();
mapping.setReferenceClass(Relation.class);
mapping.setTargetForeignKey("RELATION.PARENT_ID");
ExpressionBuilder builder = new ExpressionBuilder();
mapping.setSelectionCriteria(builder.getField("RELATIONSHIP.PARENT_ID").equal(builder.getParameter("ORGANIZATION.ORG_ID").and(builder.getField("RELATIONSHIP.RELATIONSHIP_TYPE").equal(2)));
orgDescriptor.addMapping(mapping); -
Aggregate one-to-many relationship problem
Hello,
After migrating from Toplink 9i I've stumbled across a problem with our aggregate objects.
Toplink Workbench reports no errors and generates a nice XML but in runtime I get this error whenever a aggregate function is used.
[TopLink fin]: 2008.02.13 03:18:11.552--ServerSession(12626425)--Connection(29948747)--Thread(Thread[main,5,main])--SELECT DISTINCT t0.NPL_PACK_ID, t0.NPL_ID FROM NPL_MEDPROD t3, FASS_MEDPROD t2, NPL_MEDPROD t1, NPL_PACKAGE t0 WHERE (((t0.NPL_ID = t1._Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test) AND ((t1.NPL_ID = t2.NPL_ID) AND (t3.NPL_ID LIKE '19750613000031%'))) AND (t3.NPL_ID = t2.NPL_ID))
Caused by: Undantag [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)): oracle.toplink.exceptions.DatabaseException
Internt undantag: java.sql.SQLException: ORA-00911: invalid character
Felkod: 911
I belive that problem resides in this clause :
t1._Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test
I've created a small test project with just a couple of classes but the same aggregate problem occurs which has let me to believe the problem does not come from the migrating process which was my first guess. If anyone could help me discover what I am doing wrong it would be very appreciated. Below is my test project output.
<?xml version="1.0" encoding="UTF-8"?>
<toplink:object-persistence version="Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)" xmlns:opm="http://xmlns.oracle.com/ias/xsds/opm" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:toplink="http://xmlns.oracle.com/ias/xsds/toplink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<opm:name>test</opm:name>
<opm:class-mapping-descriptors>
<opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
<opm:class>se.lif.fass.fassdata.impl.FASSMedProdImpl</opm:class>
<opm:alias>FASSMedProdImpl</opm:alias>
<opm:primary-key>
<opm:field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:primary-key>
<opm:events xsi:type="toplink:event-policy"/>
<opm:querying xsi:type="toplink:query-policy"/>
<opm:attribute-mappings>
<opm:attribute-mapping xsi:type="toplink:one-to-one-mapping">
<opm:attribute-name>_Medprod</opm:attribute-name>
<opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl</opm:reference-class>
<opm:private-owned>true</opm:private-owned>
<opm:foreign-key>
<opm:field-reference>
<opm:source-field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
<opm:target-field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:field-reference>
</opm:foreign-key>
<opm:foreign-key-fields>
<opm:field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:foreign-key-fields>
<toplink:batch-reading>true</toplink:batch-reading>
<toplink:selection-query xsi:type="toplink:read-object-query"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>id</opm:attribute-name>
<opm:read-only>true</opm:read-only>
<opm:field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:attribute-mapping>
</opm:attribute-mappings>
<toplink:descriptor-type>independent</toplink:descriptor-type>
<toplink:instantiation/>
<toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
<toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
<toplink:tables>
<toplink:table name="FASS_MEDPROD"/>
</toplink:tables>
</opm:class-mapping-descriptor>
<opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
<opm:class>schemas_npl.instance.impl.MedprodTypeImpl</opm:class>
<opm:alias>MedprodTypeImpl</opm:alias>
<opm:primary-key>
<opm:field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:primary-key>
<opm:events xsi:type="toplink:event-policy"/>
<opm:querying xsi:type="toplink:query-policy"/>
<opm:attribute-mappings>
<opm:attribute-mapping xsi:type="toplink:aggregate-object-mapping">
<opm:attribute-name>_Medprodpack</opm:attribute-name>
<toplink:reference-class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl</toplink:reference-class>
<toplink:allow-null>false</toplink:allow-null>
<toplink:field-translations>
<toplink:field-translation>
<toplink:source-field name="_Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test" xsi:type="opm:column"/>
<toplink:target-field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</toplink:field-translation>
</toplink:field-translations>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>_Nplid</opm:attribute-name>
<opm:field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>id</opm:attribute-name>
<opm:read-only>true</opm:read-only>
<opm:field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:attribute-mapping>
</opm:attribute-mappings>
<toplink:descriptor-type>independent</toplink:descriptor-type>
<toplink:instantiation/>
<toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
<toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
<toplink:tables>
<toplink:table name="NPL_MEDPROD"/>
</toplink:tables>
</opm:class-mapping-descriptor>
<opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
<opm:class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl</opm:class>
<opm:alias>MedprodTypeImpl$MedprodpackTypeImpl</opm:alias>
<opm:events xsi:type="toplink:event-policy"/>
<opm:querying xsi:type="toplink:query-policy"/>
<opm:attribute-mappings>
<opm:attribute-mapping xsi:type="toplink:one-to-many-mapping">
<opm:attribute-name>_Presentation</opm:attribute-name>
<opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:reference-class>
<opm:private-owned>true</opm:private-owned>
<opm:target-foreign-key>
<opm:field-reference>
<opm:source-field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
<opm:target-field name="_Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test" xsi:type="opm:column"/>
</opm:field-reference>
</opm:target-foreign-key>
<toplink:batch-reading>true</toplink:batch-reading>
<toplink:container xsi:type="toplink:list-container-policy">
<toplink:collection-type>com.sun.xml.bind.util.ListImpl</toplink:collection-type>
</toplink:container>
<toplink:selection-query xsi:type="toplink:read-all-query">
<toplink:container xsi:type="toplink:list-container-policy">
<toplink:collection-type>com.sun.xml.bind.util.ListImpl</toplink:collection-type>
</toplink:container>
</toplink:selection-query>
</opm:attribute-mapping>
</opm:attribute-mappings>
<toplink:descriptor-type>aggregate</toplink:descriptor-type>
<toplink:instantiation/>
<toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
<toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
</opm:class-mapping-descriptor>
<opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
<opm:class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:class>
<opm:alias>MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:alias>
<opm:primary-key>
<opm:field table="NPL_PACKAGE" name="NPL_PACK_ID" xsi:type="opm:column"/>
</opm:primary-key>
<opm:events xsi:type="toplink:event-policy"/>
<opm:querying xsi:type="toplink:query-policy"/>
<opm:attribute-mappings>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>_Nplpackid</opm:attribute-name>
<opm:field table="NPL_PACKAGE" name="NPL_PACK_ID" xsi:type="opm:column"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:one-to-one-mapping">
<opm:attribute-name>backref</opm:attribute-name>
<opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl</opm:reference-class>
<opm:foreign-key>
<opm:field-reference>
<opm:source-field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
<opm:target-field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:field-reference>
</opm:foreign-key>
<opm:foreign-key-fields>
<opm:field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
</opm:foreign-key-fields>
<toplink:indirection xsi:type="toplink:value-holder-indirection-policy"/>
<toplink:selection-query xsi:type="toplink:read-object-query"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>id</opm:attribute-name>
<opm:read-only>true</opm:read-only>
<opm:field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
</opm:attribute-mapping>
</opm:attribute-mappings>
<toplink:descriptor-type>independent</toplink:descriptor-type>
<toplink:instantiation/>
<toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
<toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
<toplink:tables>
<toplink:table name="NPL_PACKAGE"/>
</toplink:tables>
</opm:class-mapping-descriptor>
</opm:class-mapping-descriptors>
<toplink:login xsi:type="toplink:database-login">
<toplink:platform-class>oracle.toplink.platform.database.oracle.Oracle8Platform</toplink:platform-class>
<toplink:user-name>fassadmin</toplink:user-name>
<toplink:password>3CC3773C96563CA0C89634305615359CD62D1A19DF561D1E</toplink:password>
<toplink:driver-class>oracle.jdbc.driver.OracleDriver</toplink:driver-class>
<toplink:connection-url>jdbc:oracle:oci8:@DB2</toplink:connection-url>
</toplink:login>
</toplink:object-persistence>
Regards
/JonasThe issue is in the one-to-many mapping in the aggregate,
<br>
<opm:attribute-mapping xsi:type="toplink:one-to-many-mapping">
<opm:attribute-name>_Presentation</opm:attribute-name>
<opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:reference-class>
<opm:private-owned>true</opm:private-owned>
<opm:target-foreign-key>
<opm:field-reference>
<opm:source-field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
<opm:target-field name="_Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test" xsi:type="opm:column"/>
</opm:field-reference>
</opm:target-foreign-key>There is an issue with the Mapping Workbench and shared aggregates with one-to-many mappings and translating the foreign key fields. Did this work before, I would be surprized if it did, unless the 2.5 Builder was used?
Anyway the easiest workaround is to either edit the XML and change the NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test column name to what it should be, or define a descriptor amendment method to define the one-to-many mapping with the correct field names.
-- James : EclipseLink -
In my JPA project I'm using these three classes:
Cart.java:
package com.spinnaker.pedja;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
@Entity(name = "Cart")
@Table(schema = "shop")
public class Cart {
@Id
@Column(name = "cart_id")
private int Cart_id;
@Column(name = "cart_date")
private Date date;
@OneToMany(mappedBy = "cartItemPK", targetEntity = CartItemPK.class)
private Set cartitemCollection = new HashSet(0);
@ManyToOne
@JoinColumn(name = "customer_id")
private Customer customer;
public Customer getCustomer() {
return customer;
public void setCustomer(Customer customer) {
this.customer = customer;
public Cart() {
public Set getCartitemCollection() {
return cartitemCollection;
public void setCartitemCollection(Set cartitemCollection) {
this.cartitemCollection = cartitemCollection;
public int getCart_id() {
return Cart_id;
public void setCart_id(int cart_id) {
this.Cart_id = cart_id;
public Date getDate() {
return date;
public void setDate(Date date) {
this.date = date;
}, CartItem.java:
package com.spinnaker.pedja;
import java.io.Serializable;
import javax.persistence.*;
@Entity
@Table(schema = "shop")
public class CartItem implements Serializable {
@EmbeddedId
@ManyToOne
// @JoinColumn(name = "cart_id")
CartItemPK cartItemPK;
@Column(name = "quantity")
private int quantity;
@Column(name = "unit_price")
private double unit_price;
// @JoinColumn(name = "cart_id")
// private Cart cart;
// public Cart getCart() {
// return cart;
// public void setCart(Cart cart) {
// this.cart = cart;
public CartItem() {
public CartItemPK getCartItemPK() {
return cartItemPK;
public void setCartItemPK(CartItemPK cartItemPK) {
this.cartItemPK = cartItemPK;
public int getQuantity() {
return quantity;
public void setQuantity(int quantity) {
this.quantity = quantity;
public double getUnit_price() {
return unit_price;
public void setUnit_price(double unit_price) {
this.unit_price = unit_price;
}and CartItemPK.java:
package com.spinnaker.pedja;
import java.io.Serializable;
import javax.persistence.*;
@Table(schema="shop")
@Embeddable
public class CartItemPK implements Serializable{
@Column(name="item_id",nullable=false)
private int itemId;
// @ManyToOne
// @JoinColumn(name = "cart_id")
// private Cart cart;
@Column(name="cart_id",nullable=false)
private int cartId;
public int getItemId() {
return itemId;
public void setItemId(int itemId) {
this.itemId = itemId;
public int getCartId() {
return cartId;
public void setCartId(int cartId) {
this.cartId = cartId;
I'm having problem with mapping one to many relationship between Cart and CartItem.I had to introduce CartItemPK class because CartItem has composite primary key.Help please!!!In my test class I'm using this code:
Cart cart=em.find(Cart.class, 33);
Set cartItems=cart.getCartitemCollection();
for (Iterator iterator = cartItems.iterator(); iterator.hasNext();) {
CartItem cart_item = (CartItem) iterator.next();
System.out.println(cart_item.getCartItemPK().getCartId());
}and this error happens:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.spinnaker.pedja.Cart.cartitemCollection[com.spinnaker.pedja.CartItemPK]
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:247)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:159)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:95)
at com.spinnaker.pedja.test.Test.main(Test.java:30)
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.spinnaker.pedja.Cart.cartitemCollection[com.spinnaker.pedja.CartItemPK]
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:979)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:530)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:471)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1136)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1211)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:847)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:178)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:235)
... 4 more
I didn't find any example on the internet about my particular case.In the database,Cart and CartItem are conected via cart_id field.But in my JPA project,cart_id field is a part of a composite key CarItemPK. -
One-to-many relationship: problem with several tables on the one side...
Hello
I'm having problems developing a database for a content management system. Apart from details, I've got one main table, that holds the tree structure of the content ("resources") and several other tables that contain data of a particular datatype ("documents", "images", etc.). Now, there's one-to-many relationship between "resources" table and all the datatype tables - that is, in the "resources" table there's "resource_id" column, being a foreign key referenced to the "id" columns in the datatype tables.
The problem is that this design is deficient. I can't tell form the "resource_id" column from which datatype table to get the data. It seems to me that one-to-many relationship only works with two tables. If the data on the one side of the relationship is contained in several tables, problems arise.
Anybody knows a solution? I would be obliged.
Regards
HavocadoHi;
A simple way may be create a view on referenced tables:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL>
SQL> drop table resources;
Table dropped
SQL> create table resources(id number, name varchar2(12));
Table created
SQL> insert into resources values(1,'Doc....');
1 row inserted
SQL> insert into resources values(2,'Img....');
1 row inserted
SQL> drop table documents;
Table dropped
SQL> create table documents(id number, resource_id number,type varchar2(12));
Table created
SQL> insert into documents values(1,1,'txt');
1 row inserted
SQL> drop table images;
Table dropped
SQL> create table images(id number, resource_id number,path varchar2(24));
Table created
SQL> insert into images values(1,2,'/data01/images/img01.jpg');
1 row inserted
SQL> create or replace view vw_resource_ref as
2 select id, resource_id, type, null as path from documents
3 union
4 select id, resource_id, null as type, path from images;
View created
SQL> select * from resources r inner join vw_resource_ref rv on r.id = rv.resource_id;
ID NAME ID RESOURCE_ID TYPE PATH
1 Doc.... 1 1 txt
2 Img.... 1 2 /data01/images/img01.jpg
SQL> Regards.... -
One-to-many relationships problem
Hi,
I'm having some problems with one-to-many relationships.
I've a two way relationship beetwen Person and Document.
Person has a collection of Documents (1-n).
Document has an instance for Person.
In my database schema Document has a FK for person.
The problem occurs when I'm trying to save the Person object
with a collection of Documents.
Oracle gives me the following message:
ORA-00001: unique constraint (SMS.PK_PERSON) violated
In my kodo.properties file I put:
kodo.jdbc.ForeignKeyConstraints: true
It seems that when the collection of Documents is persisted, kodo tries to
save a new Person object for each Document.
When I have just one instance of Document in my collection kodo persists
it ok, but when I have move instances I get
that problem.
Can somebody help me?
Thanks in advance,
Joan CaffeeYou need to make sure each Document references the same Person object in
the JVM. JDO persists your object model as-is. Each distinct JVM
object becomes a distinct database record. You can't have multiple JVM
objects in the same PersistenceManager representing the same database
record. -
I am trying to get Container Managed Relationships working with Oracle Application Server. I am sure that the problem it quite obvious to anyone who has got this working before, but after carefully following numerous examples, I still cant get them to work. I have various issues including the application server blocking when it calls the getB() method in "A" to populate the items from table "B", even though the generated SQL looks okay e.g., "select B_PK from B where (b_fk = 1)".
I would be extremely grateful if you could point out my (hopefully obvious) mistake as I wrestled with it for the past couple of weeks.
Any ideas?
Cheers,
Jonathan
I have two tables A and B; A has a one-to-many relationship with B:
Table A:
A_PK (primary key)
A_NAME
Table B:
B_PK (primary key)
B_NAME
B_FK (foreign key to table A)
My ejb-jar.xml file is:
<ejb-jar>
<enterprise-beans>
<entity>
<description>Entity Bean ( CMP )</description>
<display-name>A</display-name>
<ejb-name>A</ejb-name>
<home>mypackage1.AHome</home>
<remote>mypackage1.A</remote>
<local-home>mypackage1.ALocalHome</local-home>
<local>mypackage1.ALocal</local>
<ejb-class>mypackage1.impl.ABean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Long</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>A</abstract-schema-name>
<cmp-field><field-name>a_pk</field-name></cmp-field>
<cmp-field><field-name>a_name</field-name></cmp-field>
<primkey-field>a_pk</primkey-field>
</entity>
<entity>
<description>Entity Bean ( CMP )</description>
<display-name>B</display-name>
<ejb-name>B</ejb-name>
<home>mypackage1.BHome</home>
<remote>mypackage1.B</remote>
<local-home>mypackage1.BLocalHome</local-home>
<local>mypackage1.BLocal</local>
<ejb-class>mypackage1.impl.BBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Long</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>B</abstract-schema-name>
<cmp-field><field-name>b_pk</field-name></cmp-field>
<cmp-field><field-name>b_name</field-name></cmp-field>
<cmp-field><field-name>b_fk</field-name></cmp-field>
<primkey-field>b_pk</primkey-field>
</entity>
</enterprise-beans>
<relationships>
<ejb-relation>
<ejb-relation-name>A-B</ejb-relation-name>
<ejb-relationship-role>
<multiplicity>One</multiplicity>
<cascade-delete/>
<relationship-role-source>
<ejb-name>A</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>b</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>B</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
</relationships>
</ejb-jar>
And my orion-ejb-jar.xml file is:
<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE orion-ejb-jar PUBLIC "-//Evermind//DTD Enterprise JavaBeans 1.1 runtime//EN" "http://xmlns.oracle.com/ias/dtds/orion-ejb-jar.dtd">
<orion-ejb-jar>
<enterprise-beans>
<entity-deployment name="A" copy-by-value="false" data-source="jdbc/Connection1DS" exclusive-write-access="false" table="a">
<primkey-mapping>
<cmp-field-mapping name="a_pk" persistence-name="a_pk"
persistence-type="int(11)"/>
</primkey-mapping>
<cmp-field-mapping name="a_pk" persistence-name="a_pk"
persistence-type="int(11)"/>
<cmp-field-mapping name="a_name" persistence-name="a_name"
persistence-type="varchar(100)"/>
<cmp-field-mapping name="b">
<collection-mapping table="B">
<primkey-mapping>
<cmp-field-mapping name="b_fk" persistence-name="B_FK"/>
</primkey-mapping>
<value-mapping type="mypackage1.BLocal">
<cmp-field-mapping>
<entity-ref home="B">
<cmp-field-mapping name="b_pk" persistence-name="B_PK"/>
</entity-ref>
</cmp-field-mapping>
</value-mapping>
</collection-mapping>
</cmp-field-mapping>
</entity-deployment>
<entity-deployment name="B" copy-by-value="false" data-source="jdbc/Connection1DS" exclusive-write-access="false" table="b">
<primkey-mapping>
<cmp-field-mapping name="b_pk" persistence-name="b_pk"
persistence-type="int(11)"/>
</primkey-mapping>
<cmp-field-mapping name="b_pk"
persistence-name="b_pk" persistence-type="int(11)"/>
<cmp-field-mapping name="b_fk" persistence-name="b_fk"
persistence-type="int(11)"/>
</entity-deployment>
</enterprise-beans>
<assembly-descriptor>
<default-method-access>
<security-role-mapping impliesAll="true" name="<default-ejb-caller-role>"/>
</default-method-access>
</assembly-descriptor>
</orion-ejb-jar>Ok, I found out something strange. If I do the addPet operation twice in the client the new relationship is created, too.
p = home.create("Violetta");
p.addNewPet("Jenny");
p = home.create("Frank");
p.addPet("Jenny");
p.addPet("Jenny");
May this be a timing problem? Or is there a command I could execute to ensure all data manipulation is populated to the DB. (Like close() in JDBC)
TIA
Frank -
Persistence and transactions: One-to-many consistency problem
Hi,
we have the following problem: We have two persistent classes A and B that are connected via a one-to-many (1:n) relationship. Now we
1. get an object "a" of class A and a number of related objects of class B from the persistence manager. Then we
3. delete the relationship between "a" and one object of class B. Then (without commit)
4. the GUI requests to show all related Bs for our given "a" and:
5. the query returns also the "deleted" object.
All these steps are performed within the same (object oriented) top level transaction.
The reason for this seems clear to us: The removal of the B has not been persisted in the DB. However, we don't really know how to deal with it...
Any suggestion is welcome.
ChristophHi Chris,
it is unclear to me if you are re-reading the database after you delete the 'b' item.
Anyway, the way persistent objects work is that changes are not written to the database until the SAP LUW ends with a COMMIT WORK.
Cheers
Graham Robbo -
Hi.
I,m trying to combine two tables into one. Table 1 is persons. Table two is movies. Table to insert in is, lets say per_mov_table
I'm building a form that will get values from both tables 1 and 2 and insert into a new one.
In that form I can select a person from a dropdown list. And select movies from a select list. Its
possible to select multiple movies per person.
I,m trying with the ADDT behaviors. but I get some strange results.
Lets say I select person nr 2 and movies 2,3 and 4 in the form. Then I would expect results in new table to be something like: (id_fk_pers id_fk_mov are the foregin keys)
id_per_mov_table id_fk_pers id_fk_mov
1 2 2
2 2 3
3 2 4
instead the output is:
id_per_mov_table id_fk_pers id_fk_mov
1 2 1
2 77 2
3 77 3
4 77 4
First it inserts a new row with som bogus value that I dont know where it comes from
Then it seemes that the id_fk_pers have som sort of autoincrement because if I do the same insert again I get
id_per_mov_table id_fk_pers id_fk_mov
1 2 1
2 80 2
3 80 3
4 80 4
So id_fk_pers is not getting the person id from the persons table. it is linked together with pers_id and id_fk_pers.
So what am I to do? I'm desperate to get this working.
I dont care how to do it but the goal is to show a detail page with one person and many movies with a ?pers_id link from another page.
Regards
Olle
ps. sorry for the long postHi.
I,m trying to combine two tables into one. Table 1 is persons. Table two is movies. Table to insert in is, lets say per_mov_table
I'm building a form that will get values from both tables 1 and 2 and insert into a new one.
In that form I can select a person from a dropdown list. And select movies from a select list. Its
possible to select multiple movies per person.
I,m trying with the ADDT behaviors. but I get some strange results.
Lets say I select person nr 2 and movies 2,3 and 4 in the form. Then I would expect results in new table to be something like: (id_fk_pers id_fk_mov are the foregin keys)
id_per_mov_table id_fk_pers id_fk_mov
1 2 2
2 2 3
3 2 4
instead the output is:
id_per_mov_table id_fk_pers id_fk_mov
1 2 1
2 77 2
3 77 3
4 77 4
First it inserts a new row with som bogus value that I dont know where it comes from
Then it seemes that the id_fk_pers have som sort of autoincrement because if I do the same insert again I get
id_per_mov_table id_fk_pers id_fk_mov
1 2 1
2 80 2
3 80 3
4 80 4
So id_fk_pers is not getting the person id from the persons table. it is linked together with pers_id and id_fk_pers.
So what am I to do? I'm desperate to get this working.
I dont care how to do it but the goal is to show a detail page with one person and many movies with a ?pers_id link from another page.
Regards
Olle
ps. sorry for the long post -
One to Many Conversion Problem
Hi Guys,
I have a source table and conataining different attributes. i want to do this thing
Source_Name=Targ_first name + Targ_Last name
Exp: Source name= Tanvir Mughal
I want to store in target table
targ_first_name=Tanvir
targ_last_name=Mughal
similer problem with address i want to break it into multiple fields
How i can do this. Should i write a query in expression operator if it is then please write that query. I am a student and working on a semester project.
Please help me i shall be thankful to you for this kind.This will work if you have 2 names only. If the guys name is 'AAAA BBBB CCCC', It won't work. Then, you'll have to use a LOOP to control it.
SQL> CREATE OR REPLACE PROCEDURE ONE_TO_MANY(V_FULL_NAME VARCHAR2) AS
2 V_FIRST_NAME VARCHAR2(50);
3 V_LAST_NAME VARCHAR2(50);
4 V_INI NUMBER;
5 V_END NUMBER;
6 V_LENGTH NUMBER;
7 BEGIN
8
9 V_LENGTH := LENGTH(V_FULL_NAME);
10 V_END := INSTR(V_FULL_NAME, ' ');
11 V_FIRST_NAME := SUBSTR(V_FULL_NAME, 1, (V_END-1));
12 V_LAST_NAME := SUBSTR(V_FULL_NAME, (V_END + 1), V_LENGTH);
13
14 DBMS_OUTPUT.PUT_LINE('FIRST NAME '||V_FIRST_NAME);
15 DBMS_OUTPUT.PUT_LINE('LAST NAME '||V_LAST_NAME);
16
17 END;
18
19 /
Procedure created.
SQL> set serveroutput on
SQL> EXEC ONE_TO_MANY('MARCOS FRANCO');
FIRST NAME MARCOS
LAST NAME FRANCO
PL/SQL procedure successfully completed. -
Struggling with a one to many relationship in a sub-report
Post Author: Scott_tansley
CA Forum: General
I have a database schema as per below: tblENQUIRY tblDatasheets tblReportParasIRSID (PK) 1 --> & IRSID (FK) UID (PK)Attribute1 SHEETID (PK) 1 > & SHEETID (FK)Attribute2 Attribute1 LIST_ORDER tblStandardParasAttribute3 Attribute2 PARA_CODE (FK) & < 1 CODE (PK)etc... Attribute3 TEXT etc...
The PROBLEM I am a Crystal Reports Newbie, and having to work through things bit by bitu2026 I've managed to achieve quite a lot, but I'm totally stuck with this and would appreciate some help. I need to create a report (essentially a letter and some datasheets) around a one-to-many relationship, which I have managed to compile using a main report (for the one [tblENQUIRY]) and sub report (for the many [tblDatasheets]). Essentially I need a covering letter, then the u2018manyu2019 datasheets, and then a number of other pages (which are largely static text). I have created a main report which includes the covering letter, holds a subreport for the datasheets, and then contains the text for the additional pages. This all works fine, and I get the correct number of datasheets for each main report. My problem stems from the use of this sub report. This sub-report needs to hold some attribute values for each datasheet, which is fine. However, on each datasheet page I need to have some paragraphs, which are held in another one to many relationship. Each datasheet may have up to six paragraphs held as a code in tblReportParas, with a relationship to the text as held in tblStandardParas. My original thought would have been to embed another sub report, containing the values from tblStandardParas!TEXT, into the first sub report. However, I have found that it is not possible to have a sub-report inside another sub-report. I had seperated the first sub-report out from the main report, and then embedded another sub-report into it. This worked fine until I tried to stitch the sub-report back into the main report (at which point the sub-sub-report dissapeared from view). I have therefore reworked my sub-report a little, and the attribution is now stored in a pageheader, with the tblStandardParas!TEXT in a detail section below it. This almost works! The only problem is that there is no relationship between the pageheader and detail sections. To clarify, I would expect to have one datasheet, with the attribution at the top, and then the six paras below. Then, the same on the next page (assuming there is a second datasheet) for that report. Instead, I get the correct attribution, but the detail section actually gives every paragraph in the database, no matter which datasheet/or report it related to! I therefore need to limit the detail section to only show those paragraphs where the SHEETID in tblReportParas is the same as the tblDatasheets SHEETID. Any offers of advice would be appreciated.Post Author: Scott_tansley
CA Forum: General
I managed to resolve this myself in the end. I moves the tblEnquiry data into report header/footer sections, this allowed me to add the tblDatasheets information into the details section, which gave me multiple pages - and then finally, the Paragraphs were added through the use of a sub report.
There's probably an even better way, but for now it works, it's quick - and so I'm going to go with it!
Thanks for your interest. -
I purchased 2 packages of gems for skylanders and only received 1 package. Got email receipts and tried to report problem with link in email on my ipad2 and it keeps coming up with to many https redirects. Can anyone help? Just want my gems :).
Contact iTunes Customer Service and request assistance
Use this Link > Apple Support iTunes Store Contact -
JPA One-To-Many Parent-Child Mapping Problem
I am trying to map an existing legacy Oracle schema that involves a base class table and two subclass tables that are related by a one-to-many relationship which is of a parent-child nature.
The following exception is generated. Can anybody provide a suggestion to fix the problem?
Exception [EclipseLink-45] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing mapping for field [BASE_OBJECT.SAMPLE_ID].
Descriptor: RelationalDescriptor(domain.example.entity.Sample --> [DatabaseTable(BASE_OBJECT), DatabaseTable(SAMPLE)])
The schema is as follows:
CREATE TABLE BASE_OBJECT(
"BASE_OBJECT_ID" INTEGER PRIMARY KEY NOT NULL,
"NAME" VARCHAR2(128) NOT NULL,
"DESCRIPTION" CLOB NOT NULL,
"BASE_OBJECT_KIND" NUMBER(5,0) NOT NULL );
CREATE TABLE SAMPLE(
"SAMPLE_ID" INTEGER PRIMARY KEY NOT NULL,
"SAMPLE_TEXT" VARCHAR2(128) NOT NULL )
CREATE TABLE SAMPLE_ITEM(
"SAMPLE_ITEM_ID" INTEGER PRIMARY KEY NOT NULL,
"SAMPLE_ID" INTEGER NOT NULL,
"QUANTITY" INTEGER NOT NULL )
The entities are related as follows:
SAMPLE.SAMPLE_ID -> BASE_OBJECT.BASE_OBJECT_ID - The PKs that are used to join the sample to the base class
SAMPLE_ITEM.SAMPLE_ITEM_ID -> BASE_OBJECT.BASE_OBJECT_ID - The PKs that are used to join the sample item to the base class
SAMPLE_ITEM.SAMPLE_ID -> SAMPLE.SAMPLE_ID - The FK that is used to join the sample item to the sample class as a child of the parent.
SAMPLE is one to many SAMPLE_ITEM
The entity classes are as follows:
@Entity
@Table( name = "BASE_OBJECT" )
@Inheritance( strategy = InheritanceType.JOINED )
@DiscriminatorColumn( name = "BASE_KIND", discriminatorType = DiscriminatorType.INTEGER )
@DiscriminatorValue( "1" )
public class BaseObject
extends SoaEntity
@Id
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "BaseObjectIdSeqGen" )
@SequenceGenerator( name = "BaseObjectIdSeqGen", sequenceName = "BASE_OBJECT_PK_SEQ", allocationSize = 1 )
@Column( name = "BASE_ID" )
private long baseObjectId = 0;
@Entity
@Table( name = "SAMPLE" )
@PrimaryKeyJoinColumn( name = "SAMPLE_ID" )
@AttributeOverride(name="baseObjectId", column=@Column(name="SAMPLE_ID"))
@DiscriminatorValue( "2" )
public class Sample
extends BaseObject
@OneToMany( cascade = CascadeType.ALL )
@JoinColumn(name="SAMPLE_ID",referencedColumnName="SAMPLE_ID")
private List<SampleItem> sampleItem = new LinkedList<SampleItem>();
@Entity
@Table( name = "SAMPLE_ITEM" )
@PrimaryKeyJoinColumn( name = "SAMPLE_ITEM_ID" )
@AttributeOverride(name="baseObjectId", column=@Column(name="SAMPLE_ITEM_ID"))
@DiscriminatorValue( "3" )
public class SampleItem
extends BaseObject
@Basic( optional = false )
@Column( name = "SAMPLE_ID" )
private long sampleId = 0;
Edited by: Chris-R on Mar 2, 2010 4:45 PMThanks for the thoroughness. There was a mistake in moving the code over for the forum. The field names are correct throughout the original source code.
BASE_OBJECT_ID is used throughout.
I suspect the problem lies in the one-to-many sampleItem(s) relationship that is based upon the subclassed item class. (The relationship is actually "sampleItems" in the real code and somehow got changed in the move over.)
The problem may lie in the mapping of the attribute override in the child class to the referencing of the item class from the parent side of the relationship in the Sample class.
I further suspect this may be specific to Eclipselink based upon other postings I've seen on the web that have similar problems...
Any thoughts?
Edited by: Chris-R on Mar 3, 2010 9:56 AM -
Business Scenario- We have a parent organization with 6 different Business Units.One BU requires 9 stages for for Opportunity(Tender) Tracking.The client requirement is to show the basic details of the tender at the header level and to show details specific to individual sales stage as different tabs.There will be multiple opportunity members added as opportunity team and will be responsible for capturing details specific to individual sales stage(tab). The Tab should be enabled and disabled based on the role. Reporting is required against each stage with specific fields of child objects against each opportunity.
We created multiple children entities under the oportunity(one to many mapping) but we are unable to add more than 3 child objects for a primary object for reporting purpose.
Kindly suggest what needs to be done to meet the requirementCan you provide the exact steps you took to "created multiple children entities under the oportunity" ?
Jani Rautiainen
Fusion Applications Developer Relations
https://blogs.oracle.com/fadevrel/ -
Why is iTunes Store not allowing me to report problems w/ one of my downloads?
Am using Internet Explorer v11.0.9600.16428 On Windows 7 PRO w/ iTunes v11.3.1.8. As far as I know, these are the latest versions of both those programs.
Why is iTunes Store not allowing me to report problems w/ one of my downloads?Clyde --
I don't have a problem viewing my purchase history. I have a problem getting support pages to work. Every time I go to get support, ie: reporting a problem with a downloaded song, my Internet Explorer 11 displays a message from the iTunes website that says I much have the latest version of Mozila, Firefox or Internet Explorer to use the support pages. Having met these requirements, why no can use support pages?
Maybe you are looking for
-
As soon as the IPOD starts to synch with ITUNES, it makes ITUNES close
My brand new 5th Gen IPOD Video makes ITUNES (7.02) close immediately after the start of the synch process. A pop window appears stating that ITUNES HAS TO CLOSE...... Can someone help !!!!
-
SP for Blocking Payment Entries in Negative Cash Account
Hi Guys, I want to Block the users while posting the Payments in Cash Accounts(Some Particular Accounts). If the Balance in the Cash Account is in negative then the system needs to show an Error Message and it should not allow the users to post the
-
Q: I want to use an XML data source to dynamically display images and data in my Flex application. I won't know how many images/data points I will have at design time. How can I best approach this? A: Depending on what you're wanting to do, you can e
-
Sorry i am not sure were to put this but i want to install sims 2 on my mac mini is there any way to install a pc game on a mac mini
-
I am using exchange 2003 connected using MAPI with outlook2010. when i send e-mail to one of my customer. i got below error message There was a SMTP communication problem with the recipient's email server. Please contact your system administrator. <