XML one to many
Hello:
Given the following XML document:
<?xml version="1.0" encoding="UTF-8"?>
<People>
<Person Gender="Male">
<Name>
<First>Clint</First>
<Last>Eastwood</Last>
</Name>
<Address>
<Street>Cowboy Court</Street>
<Number>1234</Number>
<City>Raleigh</City>
<State>NC</State>
<Zip>27615</Zip>
</Address>
</Person>
<Person Gender="Female">
<Name>
<First>Lucy</First>
<Last>Lou</Last>
</Name>
<Address>
<Street>Holly Way</Street>
<Number>4589</Number>
<City>Cary</City>
<State>NC</State>
<Zip>27876</Zip>
</Address>
</Person>
<Person Gender="Male">
<Name>
<First>Mark</First>
<Last>Manly</Last>
</Name>
<Address>
<Street>Studly Drive</Street>
<Number>9909</Number>
<City>Greensboro</City>
<State>NC</State>
<Zip>27900</Zip>
</Address>
</Person>
</People>
How could a create an XSLT (.xsl) file that would generate a seperate XML document for each
"Person" element? Everything I've read transforms one input document to one output.
I saw a reference to " xsl:result-document ", but that is only available in version 2 of XSLT.
I don't think the Java transform api supports version 2.
Thanks for your help.
here is the code that uses JDOM
I ran the test using your XML and result comes out like this
<?xml version="1.0" encoding="UTF-8"?>
<Person Gender="Male">
<Name>
<First>Clint</First>
<Last>Eastwood</Last>
</Name>
<Address>
<Street>Cowboy Court</Street>
<Number>1234</Number>
<City>Raleigh</City>
<State>NC</State>
<Zip>27615</Zip>
</address>
</Person>
<?xml version="1.0" encoding="UTF-8"?>
<Person Gender="Male">
<Name>
<First>Mark</First>
<Last>Manly</Last>
</Name>
<Address>
<Street>Studly Drive</Street>
<Number>9909</Number>
<City>Greensboro</City>
<State>NC</State>
<Zip>27900</Zip>
</address>
</Person>
public static void breakXML(String filename, String elementname)
Element root = null;
try
root = loadXMLFile(filename); //load xml file
List children = root.getChildElements(elementname);
for (int i = 0; i < children.size(); i++)
Element child = (Element)children.get(i);
child.detach();
Document doc = new Document(child);
//finally output to a file as your choice
XMLOutputter writer = new XMLOutputter(Format.getPrettyFormat());
// OutputStream out = new FileOutputStream("dummy.txt");
writer.output(doc, System.out);
// out.flush();
// out.close();
catch (Exception e)
e.printStackTrace();
public static Element loadXMLFile(String filename)
Element element = null;
InputStream in = null;
if (!(new File(filename).exists()))
System.err.println("file name can not be null");
try
SAXBuilder builder = new SAXBuilder(false);
Document doc = builder.build(in = new FileInputStream(filename));
element = doc.getRootElement();
catch(Exception e)
e.printStackTrace();
finally
try {
if (null != in) in.close();
} catch (IOException ignored) { }
return element;
public static void main(String[] s)
breakXML("testxml.txt", "Person");
}-----------
Similar Messages
-
Weblogic-cmp-rdbms-jar.xml for One-To-Many unidirectional relationship
hi,
I am trying to create a simple cmp One-To-Many unidirectional relationship and deploy the same in weblogic. Can someone help me with the weblogic-cmp-rdbms-jar.xml. Am attaching the weblogic-cmp-rdbms-jar. xml tht i am using as also the corresponding ejb-jar.xml. Pls. note tht i want a unidirectional relationship here. one i am tryng However i get this error:
Error while reading 'META-INF/weblogic-cmp-rdbms-jar.xml'. The error was: Role 'Supplier supplies Products' of relationship 'Product Supplier' contains an invalid key-column value of 'productID'. The key-column must specify a primary key column in the related bean. However, there is no primary key column named 'productID' defined in the related bean 'ProductEJB' or else 'productID' is not being recognized due to case mismatch. My weblogic-cmp-rdbms-jar
<?xml version="1.0"?>
<!DOCTYPE weblogic-rdbms-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB RDBMS Persistence//EN' 'http://www.bea.com/servers/wls810/dtd/weblogic-rdbms-jar.dtd'>
<weblogic-rdbms-jar>
<weblogic-rdbms-bean>
<ejb-name>SupplierEJB</ejb-name>
<data-source-name>RJDataSource</data-source-name>
<table-map>
<table-name>AA_Supplier</table-name>
<field-map>
<cmp-field>supplierID</cmp-field>
<dbms-column>supplierID</dbms-column>
</field-map>
<field-map>
<cmp-field>name</cmp-field>
<dbms-column>name</dbms-column>
</field-map>
</table-map>
</weblogic-rdbms-bean>
<weblogic-rdbms-bean>
<ejb-name>ProductEJB</ejb-name>
<data-source-name>RJDataSource</data-source-name>
<table-map>
<table-name>AA_Product</table-name>
<field-map>
<cmp-field>productID</cmp-field>
<dbms-column>productid</dbms-column>
</field-map>
<field-map>
<cmp-field>description</cmp-field>
<dbms-column>description</dbms-column>
</field-map>
<field-map>
<cmp-field>basePrice</cmp-field>
<dbms-column>baseprice</dbms-column>
</field-map>
<field-map>
<cmp-field>name</cmp-field>
<dbms-column>name</dbms-column>
</field-map>
<field-map>
<cmp-field>supplierID</cmp-field>
<dbms-column>supplierID</dbms-column>
</field-map>
</table-map>
</weblogic-rdbms-bean>
<weblogic-rdbms-relation>
<relation-name>Product Supplier</relation-name>
<weblogic-relationship-role>
<relationship-role-name>Supplier supplies Products</relationship-role-name>
<relationship-role-map>
<column-map>
<foreign-key-column>supplierID</foreign-key-column>
<key-column>productID</key-column>
</column-map>
</relationship-role-map>
</weblogic-relationship-role>
<weblogic-relationship-role>
<relationship-role-name>Product supplied by Supplier</relationship-role-name>
<relationship-role-map>
<column-map>
<foreign-key-column>products</foreign-key-column>
<key-column>supplierID</key-column>
</column-map>
</relationship-role-map>
</weblogic-relationship-role>
</weblogic-rdbms-relation>
</weblogic-rdbms-jar> My ejb-jar.xml
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>SupplierEJB</ejb-name>
<home>com.tpt.practice.entityBeans.cmp.product.relationship.SupplierHome</home>
<remote>com.tpt.practice.entityBeans.cmp.product.relationship.Supplier</remote>
<ejb-class>com.tpt.practice.entityBeans.cmp.product.relationship.SupplierEJB</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>AA_Supplier</abstract-schema-name>
<cmp-field>
<field-name>supplierID</field-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
</cmp-field>
<primkey-field>supplierID</primkey-field>
<ejb-ref>
<ejb-ref-name>ProducEJB</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.tpt.practice.entityBeans.cmp.product.ProductHome</home>
<remote>com.tpt.practice.entityBeans.cmp.product.Product</remote>
<ejb-link>ProductEJB#ProductEJB.jar</ejb-link>
</ejb-ref>
<query>
<query-method>
<method-name>findByName</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(a) FROM AA_Supplier AS a WHERE a.name =
?1]]>
</ejb-ql>
</query>
<query>
<query-method>
<method-name>findAllSuppliers</method-name>
<method-params>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(a) FROM AA_Supplier AS a WHERE a.supplierID
IS NOT NULL]]>
</ejb-ql>
</query>
</entity>
<entity>
<ejb-name>ProductEJB</ejb-name>
<home>com.tpt.practice.entityBeans.cmp.product.relationship.ProductHome</home>
<remote>com.tpt.practice.entityBeans.cmp.product.relationship.Product</remote>
<local-home>com.tpt.practice.entityBeans.cmp.product.relationship.ProductLocalHome</local-home>
<local>com.tpt.practice.entityBeans.cmp.product.relationship.ProductLocal</local>
<ejb-class>com.tpt.practice.entityBeans.cmp.product.relationship.ProductEJB</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>com.tpt.practice.entityBeans.cmp.product.relationship.ProductPK</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>AA_Product</abstract-schema-name>
<cmp-field>
<field-name>productID</field-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
</cmp-field>
<cmp-field>
<field-name>description</field-name>
</cmp-field>
<cmp-field>
<field-name>basePrice</field-name>
</cmp-field>
<cmp-field>
<field-name>supplierID</field-name>
</cmp-field>
<primkey-field>productID</primkey-field>
<query>
<query-method>
<method-name>findByName</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.name =
?1]]>
</ejb-ql>
</query>
<query>
<query-method>
<method-name>findByDescription</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.description
= ?1]]>
</ejb-ql>
</query>
<query>
<query-method>
<method-name>findByBasePrice</method-name>
<method-params>
<method-param>double</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.basePrice =
?1]]>
</ejb-ql>
</query>
<query>
<query-method>
<method-name>findExpensiveProducts</method-name>
<method-params>
<method-param>double</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.basePrice >
?1]]>
</ejb-ql>
</query>
<query>
<query-method>
<method-name>findCheapProducts</method-name>
<method-params>
<method-param>double</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.basePrice <
?1]]>
</ejb-ql>
</query>
<query>
<query-method>
<method-name>findAllProducts</method-name>
<method-params>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.productID
IS NOT NULL]]>
</ejb-ql>
</query>
</entity>
</enterprise-beans>
<relationships>
<ejb-relation>
<ejb-relation-name>Product Supplier</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>Supplier supplies Products</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>SupplierEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>products</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>Product supplied by Supplier</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>ProductEJB</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
</relationships>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>SupplierEJB</ejb-name>
<method-intf>Remote</method-intf>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>I think u r some confusion with productID and SuppliedID . primary key of one column( productId ) can be a foreign key of other table colum( SuppliedID). but foreign key( SuppliedID) can not be a primary key of second table .u declared SuppliedId as primary key . so ur mapping is incorrect.
-
Unable to read one-to-many relations using Hibernate
Hi,
I am trying with a very simple one-to-many relationship. When I am storing the objects, there are no problems. But when I am trying to read out the collection, it says invalid descriptor index. Please help.
Regards,
Hibernate version:
hibernate-3.1rc2
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Parent">
<id name="id">
<generator class="identity"/>
</id>
<set name="children">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>
</class>
<class name="Child">
<id name="id">
<generator class="identity"/>
</id>
<property name="name"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
The Parent class:
public class Parent
private Long id ;
private Set children;
Parent(){}
public Long getId()
return id;
public void setId(Long id)
this.id=id;
public Set getChildren()
return children;
public void setChildren(Set children)
this.children=children;
The Child class:
public class Child
private Long id;
private String name;
Child(){}
public Long getId()
return id;
private void setId(Long id)
this.id=id;
public String getName()
return name;
public void setName(String name)
this.name=name;
The Main class:
public class PCManager
public static void main(String[] args)
PCManager mgr = new PCManager();
List lt = null;
if (args[0].equals("store"))
mgr.createAndStoreParent(new HashSet(3));
else if (args[0].equals("list"))
mgr.listEvents();
HibernateUtil.getSessionFactory().close();
private void createAndStoreParent(HashSet s)
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
Parent p1 = new Parent();
int size = 3;
for (int i=size; i>0; i--)
Child c = new Child();
c.setName("Child"+i);
s.add(c);
p1.setChildren (s);
Iterator elems = s.iterator();
do {
Child ch = (Child) elems.next();
HibernateUtil.getSessionFactory().getCurrentSession().save(ch);
}while(elems.hasNext());
HibernateUtil.getSessionFactory().getCurrentSession().save(p1);
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
private void listEvents()
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
Parent result = (Parent) HibernateUtil.getSessionFactory().getCurrentSession().load(Parent.class, new Long(1));
System.out.println("Id is :"+ result.getId());
Set children = result.getChildren();
Iterator elems = children.iterator();
do {
Child ch = (Child) elems.next();
System.out.println("Child Name"+ ch.getName());
}while(elems.hasNext());
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
Full stack trace of any exception that occurs:
When I run with "hbm2ddl.auto" property as validate and trying to list the contents, I get the following out put.
C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc2\MyHibernate>ant run -Da
ction=list
Buildfile: build.xml
clean:
[delete] Deleting directory C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin
[mkdir] Created dir: C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc
2\MyHibernate\bin
copy-resources:
[copy] Copying 4 files to C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin
compile:
[javac] Compiling 5 source files to C:\Documents and Settings\mirza\Desktop\
hibernate-3.1rc2\MyHibernate\bin
run:
[java] 09:09:23,433 INFO Environment:474 - Hibernate 3.1 rc2
[java] 09:09:23,449 INFO Environment:489 - loaded properties from resource
hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate
.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.dial
ect=org.hibernate.dialect.SQLServerDialect, hibernate.max_fetch_depth=1, hiberna
te.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.
substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.cac
he.region_prefix=hibernate.test, hibernate.jdbc.batch_versioned_data=true, hiber
nate.connection.pool_size=1}
[java] 09:09:23,465 INFO Environment:519 - using java.io streams to persis
t binary types
[java] 09:09:23,465 INFO Environment:520 - using CGLIB reflection optimize
r
[java] 09:09:23,481 INFO Environment:550 - using JDK 1.4 java.sql.Timestam
p handling
[java] 09:09:23,559 INFO Configuration:1257 - configuring from resource: /
hibernate.cfg.xml
[java] 09:09:23,559 INFO Configuration:1234 - Configuration resource: /hib
ernate.cfg.xml
[java] 09:09:23,872 INFO Configuration:460 - Reading mappings from resourc
e: PCMapping.hbm.xml
[java] 09:09:24,013 INFO HbmBinder:266 - Mapping class: Parent -> Parent
[java] 09:09:24,045 INFO HbmBinder:266 - Mapping class: Child -> Child
[java] 09:09:24,045 INFO Configuration:1368 - Configured SessionFactory: n
ull
[java] 09:09:24,061 INFO Configuration:1014 - processing extends queue
[java] 09:09:24,061 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:09:24,061 INFO HbmBinder:2233 - Mapping collection: Parent.child
ren -> Child
[java] 09:09:24,076 INFO Configuration:1027 - processing association prope
rty references
[java] 09:09:24,076 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:09:24,155 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 1
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:45 - autocommit m
ode: false
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:80 - using driver
: sun.jdbc.odbc.JdbcOdbcDriver at URL: jdbc:odbc:MySQL
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:86 - connection p
roperties: {}
[java] 09:09:24,264 INFO SettingsFactory:77 - RDBMS: Microsoft SQL Server,
version: 08.00.0194
[java] 09:09:24,264 INFO SettingsFactory:78 - JDBC driver: JDBC-ODBC Bridg
e (SQLSRV32.DLL), version: 2.0001 (03.85.1117)
[java] 09:09:24,296 INFO Dialect:100 - Using dialect: org.hibernate.dialec
t.SQLServerDialect
[java] 09:09:24,311 INFO TransactionFactoryFactory:31 - Using default tran
saction strategy (direct JDBC transactions)
[java] 09:09:24,327 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of read-write or transaction
al second-level cache is not recommended)
[java] 09:09:24,327 INFO SettingsFactory:125 - Automatic flush during befo
reCompletion(): disabled
[java] 09:09:24,327 INFO SettingsFactory:129 - Automatic session close at
end of transaction: disabled
[java] 09:09:24,343 INFO SettingsFactory:144 - Scrollable result sets: ena
bled
[java] 09:09:24,343 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): d
isabled
[java] 09:09:24,343 INFO SettingsFactory:160 - Connection release mode: au
to
[java] 09:09:24,358 INFO SettingsFactory:184 - Maximum outer join fetch de
pth: 1
[java] 09:09:24,358 INFO SettingsFactory:187 - Default batch fetch size: 1
[java] 09:09:24,358 INFO SettingsFactory:191 - Generate SQL with comments:
disabled
[java] 09:09:24,358 INFO SettingsFactory:195 - Order SQL updates by primar
y key: disabled
[java] 09:09:24,358 INFO SettingsFactory:338 - Query translator: org.hiber
nate.hql.ast.ASTQueryTranslatorFactory
[java] 09:09:24,374 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTran
slatorFactory
[java] 09:09:24,374 INFO SettingsFactory:203 - Query language substitution
s: {no='N', yes='Y'}
[java] 09:09:24,374 INFO SettingsFactory:209 - Second-level cache: enabled
[java] 09:09:24,374 INFO SettingsFactory:213 - Query cache: disabled
[java] 09:09:24,374 INFO SettingsFactory:325 - Cache provider: org.hiberna
te.cache.HashtableCacheProvider
[java] 09:09:24,374 INFO SettingsFactory:228 - Optimize cache for minimal
puts: disabled
[java] 09:09:24,374 INFO SettingsFactory:233 - Cache region prefix: hibern
ate.test
[java] 09:09:24,405 INFO SettingsFactory:237 - Structured second-level cac
he entries: disabled
[java] 09:09:24,437 INFO SettingsFactory:257 - Echoing all SQL to stdout
[java] 09:09:24,452 INFO SettingsFactory:264 - Statistics: disabled
[java] 09:09:24,452 INFO SettingsFactory:268 - Deleted entity synthetic id
entifier rollback: disabled
[java] 09:09:24,452 INFO SettingsFactory:283 - Default entity-mode: POJO
[java] 09:09:24,593 INFO SessionFactoryImpl:155 - building session factory
[java] 09:09:24,938 INFO SessionFactoryObjectFactory:82 - Not binding fact
ory to JNDI, no JNDI name configured
[java] 09:09:24,954 INFO SchemaValidator:99 - Running schema validator
[java] 09:09:24,954 INFO SchemaValidator:107 - fetching database metadata
[java] 09:09:24,954 INFO Configuration:1014 - processing extends queue
[java] 09:09:24,954 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:09:24,954 INFO Configuration:1027 - processing association prope
rty references
[java] 09:09:24,954 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:09:24,985 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState
: S1002
[java] 09:09:24,985 ERROR JDBCExceptionReporter:72 - [Microsoft][ODBC SQL S
erver Driver]Invalid Descriptor Index
[java] 09:09:25,001 ERROR SchemaValidator:129 - Error closing connection
[java] java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid transaction state
[java] Initial SessionFactory creation failed.org.hibernate.exception.Gener
icJDBCException: could not get table metadata: Child
[java] java.lang.ExceptionInInitializerError
[java] at HibernateUtil.<clinit>(Unknown Source)
[java] at PCManager.listEvents(Unknown Source)
[java] at PCManager.main(Unknown Source)
[java] Caused by: org.hibernate.exception.GenericJDBCException: could not g
et table metadata: Child
[java] at org.hibernate.exception.SQLStateConverter.handledNonSpecificE
xception(SQLStateConverter.java:91)
[java] at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)
[java] at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
[java] at sun.jdbc.odbc.JdbcOdbc.SQLDisconnect(JdbcOdbc.java:2988)
[java] at sun.jdbc.odbc.JdbcOdbcDriver.disconnect(JdbcOdbcDriver.java:9
80)
[java] at sun.jdbc.odbc.JdbcOdbcConnection.close(JdbcOdbcConnection.jav
a:739)
[java] at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaVal
idator.java:125)
[java] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryIm
pl.java:299)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
tion.java:1145)
[java] at HibernateUtil.<clinit>(Unknown Source)
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateCon
verter.java:79)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:43)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:29)
[java] at org.hibernate.tool.hbm2ddl.DatabaseMetadata.getTableMetadata(
DatabaseMetadata.java:100)
[java] at org.hibernate.cfg.Configuration.validateSchema(Configuration.
java:946)
[java] at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaVal
idator.java:116)
[java] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryIm
pl.java:299)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
tion.java:1145)
[java] ... 3 more
[java] Caused by: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver
]Invalid Descriptor Index
[java] at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)
[java] at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
[java] at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3862)
[java] at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultS
et.java:5561)
[java] at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.j
ava:338)
[java] at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.j
ava:395)
[java] at PCManager.listEvents(Unknown Source)
[java] at PCManager.main(Unknown Source)
[java] at org.hibernate.tool.hbm2ddl.TableMetadata.<init>(TableMetadata
.java:30)
[java] at org.hibernate.tool.hbm2ddl.DatabaseMetadata.getTableMetadata(
DatabaseMetadata.java:85)
[java] ... 7 more
[java] Exception in thread "main"
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 4 seconds
Name and version of the database you are using:
Microsoft SQLServer2000
The generated SQL (show_sql=true):
When the program is run with "hbm2ddl.auto" property as create, I get the following output.
C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc2\MyHibernate>ant run -Daction=store
Buildfile: build.xml
clean:
[delete] Deleting directory C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin
[mkdir] Created dir: C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc
2\MyHibernate\bin
copy-resources:
[copy] Copying 4 files to C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin
compile:
[javac] Compiling 5 source files to C:\Documents and Settings\mirza\Desktop\
hibernate-3.1rc2\MyHibernate\bin
run:
[java] 09:12:54,820 INFO Environment:474 - Hibernate 3.1 rc2
[java] 09:12:54,836 INFO Environment:489 - loaded properties from resource
hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate
.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.dial
ect=org.hibernate.dialect.SQLServerDialect, hibernate.max_fetch_depth=1, hiberna
te.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.
substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.cac
he.region_prefix=hibernate.test, hibernate.jdbc.batch_versioned_data=true, hiber
nate.connection.pool_size=1}
[java] 09:12:54,852 INFO Environment:519 - using java.io streams to persis
t binary types
[java] 09:12:54,852 INFO Environment:520 - using CGLIB reflection optimize
r
[java] 09:12:54,867 INFO Environment:550 - using JDK 1.4 java.sql.Timestam
p handling
[java] 09:12:54,946 INFO Configuration:1257 - configuring from resource: /
hibernate.cfg.xml
[java] 09:12:54,946 INFO Configuration:1234 - Configuration resource: /hib
ernate.cfg.xml
[java] 09:12:55,259 INFO Configuration:460 - Reading mappings from resourc
e: PCMapping.hbm.xml
[java] 09:12:55,400 INFO HbmBinder:266 - Mapping class: Parent -> Parent
[java] 09:12:55,447 INFO HbmBinder:266 - Mapping class: Child -> Child
[java] 09:12:55,447 INFO Configuration:1368 - Configured SessionFactory: n
ull
[java] 09:12:55,447 INFO Configuration:1014 - processing extends queue
[java] 09:12:55,447 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:12:55,447 INFO HbmBinder:2233 - Mapping collection: Parent.child
ren -> Child
[java] 09:12:55,463 INFO Configuration:1027 - processing association prope
rty references
[java] 09:12:55,479 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:12:55,557 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[java] 09:12:55,557 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 1
[java] 09:12:55,557 INFO DriverManagerConnectionProvider:45 - autocommit m
ode: false
[java] 09:12:55,573 INFO DriverManagerConnectionProvider:80 - using driver
: sun.jdbc.odbc.JdbcOdbcDriver at URL: jdbc:odbc:MySQL
[java] 09:12:55,573 INFO DriverManagerConnectionProvider:86 - connection p
roperties: {}
[java] 09:12:55,651 INFO SettingsFactory:77 - RDBMS: Microsoft SQL Server,
version: 08.00.0194
[java] 09:12:55,667 INFO SettingsFactory:78 - JDBC driver: JDBC-ODBC Bridg
e (SQLSRV32.DLL), version: 2.0001 (03.85.1117)
[java] 09:12:55,682 INFO Dialect:100 - Using dialect: org.hibernate.dialec
t.SQLServerDialect
[java] 09:12:55,698 INFO TransactionFactoryFactory:31 - Using default tran
saction strategy (direct JDBC transactions)
[java] 09:12:55,714 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of read-write or transaction
al second-level cache is not recommended)
[java] 09:12:55,714 INFO SettingsFactory:125 - Automatic flush during befo
reCompletion(): disabled
[java] 09:12:55,714 INFO SettingsFactory:129 - Automatic session close at
end of transaction: disabled
[java] 09:12:55,729 INFO SettingsFactory:144 - Scrollable result sets: ena
bled
[java] 09:12:55,729 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): d
isabled
[java] 09:12:55,745 INFO SettingsFactory:160 - Connection release mode: au
to
[java] 09:12:55,745 INFO SettingsFactory:184 - Maximum outer join fetch de
pth: 1
[java] 09:12:55,745 INFO SettingsFactory:187 - Default batch fetch size: 1
[java] 09:12:55,745 INFO SettingsFactory:191 - Generate SQL with comments:
disabled
[java] 09:12:55,745 INFO SettingsFactory:195 - Order SQL updates by primar
y key: disabled
[java] 09:12:55,745 INFO SettingsFactory:338 - Query translator: org.hiber
nate.hql.ast.ASTQueryTranslatorFactory
[java] 09:12:55,777 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTran
slatorFactory
[java] 09:12:55,792 INFO SettingsFactory:203 - Query language substitution
s: {no='N', yes='Y'}
[java] 09:12:55,792 INFO SettingsFactory:209 - Second-level cache: enabled
[java] 09:12:55,792 INFO SettingsFactory:213 - Query cache: disabled
[java] 09:12:55,792 INFO SettingsFactory:325 - Cache provider: org.hiberna
te.cache.HashtableCacheProvider
[java] 09:12:55,808 INFO SettingsFactory:228 - Optimize cache for minimal
puts: disabled
[java] 09:12:55,808 INFO SettingsFactory:233 - Cache region prefix: hibern
ate.test
[java] 09:12:55,808 INFO SettingsFactory:237 - Structured second-level cac
he entries: disabled
[java] 09:12:55,839 INFO SettingsFactory:257 - Echoing all SQL to stdout
[java] 09:12:55,839 INFO SettingsFactory:264 - Statistics: disabled
[java] 09:12:55,839 INFO SettingsFactory:268 - Deleted entity synthetic id
entifier rollback: disabled
[java] 09:12:55,839 INFO SettingsFactory:283 - Default entity-mode: POJO
[java] 09:12:55,980 INFO SessionFactoryImpl:155 - building session factory
[java] 09:12:56,325 INFO SessionFactoryObjectFactory:82 - Not binding fact
ory to JNDI, no JNDI name configured
[java] 09:12:56,341 INFO Configuration:1014 - processing extends queue
[java] 09:12:56,341 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:12:56,341 INFO Configuration:1027 - processing association prope
rty references
[java] 09:12:56,341 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:12:56,356 INFO Configuration:1014 - processing extends queue
[java] 09:12:56,356 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:12:56,356 INFO Configuration:1027 - processing association prope
rty references
[java] 09:12:56,372 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:12:56,372 INFO SchemaExport:153 - Running hbm2ddl schema export
[java] 09:12:56,388 DEBUG SchemaExport:171 - import file not found: /import
.sql
[java] 09:12:56,388 INFO SchemaExport:180 - exporting generated schema to
database
[java] 09:12:56,403 DEBUG SchemaExport:283 -
[java] alter table Child
[java] drop constraint FK3E104FC976A59A
[java] 09:12:56,466 DEBUG SchemaExport:283 -
[java] drop table Child
[java] 09:12:56,544 DEBUG SchemaExport:283 -
[java] drop table Parent
[java] 09:12:56,654 DEBUG SchemaExport:283 -
[java] create table Child (
[java] id numeric(19,0) identity not null,
[java] name varchar(255) null,
[java] parent_id numeric(19,0) null,
[java] primary key (id)
[java] )
[java] 09:12:56,779 DEBUG SchemaExport:283 -
[java] create table Parent (
[java] id numeric(19,0) identity not null,
[java] primary key (id)
[java] )
[java] 09:12:56,873 DEBUG SchemaExport:283 -
[java] alter table Child
[java] add constraint FK3E104FC976A59A
[java] foreign key (parent_id)
[java] references Parent
[java] 09:12:56,952 INFO SchemaExport:200 - schema export complete
[java] 09:12:56,952 WARN JDBCExceptionReporter:48 - SQL Warning: 5701, SQL
State: 01000
[java] 09:12:56,952 WARN JDBCExceptionReporter:49 - [Microsoft][ODBC SQL S
erver Driver][SQL Server]Changed database context to 'master'.
[java] 09:12:56,952 WARN JDBCExceptionReporter:48 - SQL Warning: 5703, SQL
State: 01000
[java] 09:12:56,952 WARN JDBCExceptionReporter:49 - [Microsoft][ODBC SQL S
erver Driver][SQL Server]Changed language setting to us_english.
[java] 09:12:56,983 INFO SessionFactoryImpl:432 - Checking 0 named queries
[java] Hibernate:
[java] insert
[java] into
[java] Child
[java] (name)
[java] values
[java] (?) select
[java] scope_identity()
[java] Hibernate:
[java] insert
[java] into
[java] Child
[java] (name)
[java] values
[java] (?) select
[java] scope_identity()
[java] Hibernate:
[java] insert
[java] into
[java] Child
[java] (name)
[java] values
[java] (?) select
[java] scope_identity()
[java] Hibernate:
[java] insert
[java] into
[java] Parent
[java] default
[java] values
[java] select
[java] scope_identity()
[java] Hibernate:
[java] update
[java] Child
[java] set
[java] parent_id=?
[java] where
[java] id=?
[java] Hibernate:
[java] update
[java] Child
[java] set
[java] parent_id=?
[java] where
[java] id=?
[java] Hibernate:
[java] update
[java] Child
[java] set
[java] parent_id=?
[java] where
[java] id=?
[java] 09:12:57,390 INFO SessionFactoryImpl:831 - closing
[java] 09:12:57,390 INFO DriverManagerConnectionProvider:147 - cleaning up
connection pool: jdbc:odbc:MySQL
BUILD SUCCESSFUL
Total time: 5 seconds
Debug level Hibernate log excerpt:
Included in the above description.That's not the right mapping for the 1:m relationship in Hibernate.
First of all, I believe the recommendation is to have a separate .hbm.xml file for each class, so you should have one for Parent and Child.
Second, you'll find the proper syntax for a one-to-many relationship here:
http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html#tutorial-associations
See if those help.
The tutorial docs for Hibernate are quite good. I'd recommend going through them carefully.
% -
One to many relation doesn't work
I tried without success to get a simple one to many relationship to work.
The select works fine but
I still have problems with insert.
I have two tables on a existing schema:
1 ANAG (ID_ANAG primary key,...)
2 INDI (ID_INDI primary key, ID_ENTITA,...), where INDI.ID_ENTITA points
to ANAG.ID_ANAG
the two classes are:
1 public class Anagrafica
private int idAnag; //ID_ANAG
private String ragSoc;
private String ragSocFonet;
private String codFisc;
private String sesso;
private Integer codTit;
private Date dtNasc;
private HashSet indis;
2 public class Indirizzo
private int idIndi; //ID_INDI
private long idEntita; //ID_ENTITA
private long tpEntita;
private String indirizzo;
private String localita;
private String prov;
private String cap;
private Anagrafica anagrafica;
the two metadata:
1 anagrafica.jdo:
<?xml version="1.0"?>
<!-- This JDO Metadata file was auto-generated on 08/10/02 17.44.
See http://www.solarmetric.com for Kodo JDO Documentation and examples. -->
<jdo>
<package name="domain">
<class name="Anagrafica"
identity-type="application"
objectid-class="domain.AnagraficaPK">
<extension key="table" value="ANAG" vendor-name="kodo"/>
<extension key="class-column" value="none" vendor-name="kodo"/>
<extension key="lock-column" value="none" vendor-name="kodo"/>
<field name="idAnag" primary-key="true">
<extension key="data-column" value="ID_ANAG"
vendor-name="kodo"/>
</field>
<field name="ragSoc">
<extension key="data-column" value="RAG_SOC"
vendor-name="kodo"/>
</field>
<field name="ragSocFonet">
<extension key="data-column" value="RAG_SOC_FONET"
vendor-name="kodo"/>
</field>
<field name="codFisc">
<extension key="data-column" value="COD_FISC"
vendor-name="kodo"/>
</field>
<field name="sesso">
<extension key="data-column" value="SESSO"
vendor-name="kodo"/>
</field>
<field name="codTit">
<extension key="data-column" value="COD_TIT"
vendor-name="kodo"/>
</field>
<field name="dtNasc">
<extension key="data-column" value="DT_NASC"
vendor-name="kodo"/>
</field>
<field name="indis">
<collection element-type="domain.Indirizzo"/>
<extension vendor-name="kodo" key="table" value="INDI"/>
<extension vendor-name="kodo" key="inverse"
value="anagrafica"/>
<extension vendor-name="kodo" key="idEntita-ref-column"
value="ID_ANAG"/>
</field>
</class>
</package>
</jdo>
2 Indirizzo.jdo
<?xml version="1.0"?>
<!-- This JDO Metadata file was auto-generated on 08/10/02 17.21.
See http://www.solarmetric.com for Kodo JDO Documentation and examples. -->
<jdo>
<package name="domain">
<class name="Indirizzo"
identity-type="application" objectid-class="domain.IndiPK">
<extension key="table" value="INDI" vendor-name="kodo"/>
<extension key="class-column" value="none" vendor-name="kodo"/>
<extension key="lock-column" value="none" vendor-name="kodo"/>
<!--extension vendor-name="kodo" key="idEntita-data-column"
value="ID_ENTITA"/-->
<field name="idIndi" primary-key="true">
<extension key="data-column" value="ID_INDI"
vendor-name="kodo"/>
</field>
<field name="idEntita">
<extension key="data-column" value="ID_ENTITA"
vendor-name="kodo"/>
</field>
<field name="tpEntita">
<extension key="data-column" value="TP_ENTITA"
vendor-name="kodo"/>
</field>
<field name="indirizzo">
<extension key="data-column" value="INDIRIZZO"
vendor-name="kodo"/>
</field>
<field name="localita">
<extension key="data-column" value="LOCALITA"
vendor-name="kodo"/>
</field>
<field name="prov">
<extension key="data-column" value="PROV"
vendor-name="kodo"/>
</field>
<field name="cap">
<extension key="data-column" value="CAP"
vendor-name="kodo"/>
</field>
<field name="anagrafica">
<extension vendor-name="kodo" key="idAnag-data-column"
value="ID_ENTITA"/>
</field>
</class>
</package>
</jdo>
The problem is:
I create a new Anagrafica object and then I try to save it in the
database. These are the SQL
statements that are generated:
INSERT INTO ANAG(DT_NASC, COD_FISC, RAG_SOC_FONET, SESSO, ID_ANAG,
RAG_SOC, COD_TIT)
VALUES (NULL, NULL, 'NATALE', NULL, 971963921, 'Natale', NULL)
INSERT INTO INDI(TP_ENTITA, PROV, LOCALITA, ID_ENTITA, ID_INDI, INDIRIZZO,
CAP)
VALUES (0, NULL, NULL, 0, 971963921, 'via 25 dicembre', NULL)
Why is the value of ID_ANAG (971963921) assigned to ID_INDI and not to
ID_ENTITA?
Regards
MirkoAbe White wrote:
<field name="indis">
<collection element-type="domain.Indirizzo"/>
<extension vendor-name="kodo" key="table" value="INDI"/>
<extension vendor-name="kodo" key="inverse"
value="anagrafica"/>
<extension vendor-name="kodo" key="idEntita-ref-column"
value="ID_ANAG"/>
</field>
Get rid of all extensions except the inverse:
<field name="indis">
<collection element-type="domain.Indirizzo"/>
<extension vendor-name="kodo" key="inverse" value="anagrafica"/>
</field>
As in the examples in our documentation, all 1-many relations should only
list their inverse 1-1 relation.
Also, make sure your object model is consistent; i.e. make sure you'resetting
both sides of the relation:
indi.setAnagrafica (anag);
anag.getIndis ().add (indi);
Let us know if you continue to have problems.Hi Abe,
I got rid of the unnecessary extensions and I set both sides of the
relation as you suggest but I still have the same problem:
INSERT INTO ANAG(ID_ANAG) VALUES (2088176453)
INSERT INTO INDI(ID_INDI, ID_ENTITA) VALUES (2088176453, NULL)
while I expect
INSERT INTO ANAG(ID_ANAG) VALUES (2088176453)
INSERT INTO INDI(ID_INDI, ID_ENTITA) VALUES (<some ID>, 2088176453)
any ideas?
regards -
Context Problem when using Use One As Many
Hi SapGuru's.
i have got a requirement in an IDOC To File Interface where the segments in the IDOC are like E1LFA1M->E1LFM1M->E1WYT3M
THE Test data is like below
<?xml version="1.0" encoding="UTF-8"?>
<ns0:IDOC_Test_Mt xmlns:ns0="urn:sap.shoprite.co.za:ecc.md">
<ZCREMAS>
<IDOC>
<E1LFA1M>
<LIFNR>0000641065</LIFNR>
<E1LFM1M>
<EKORG>1001</EKORG>
<E1WYT3M>
<PARVW>BA</PARVW>
</E1WYT3M>
<E1WYT3M>
<PARVW>LF</PARVW>
</E1WYT3M>
<E1WYT3M>
<PARVW>RS</PARVW>
</E1WYT3M>
</E1LFM1M>
</E1LFA1M>
<E1LFA1M>
<LIFNR>0000641065</LIFNR>
<E1LFM1M>
<EKORG>1002</EKORG>
<E1WYT3M>
<PARVW>BA</PARVW>
</E1WYT3M>
<E1WYT3M>
<PARVW>RS</PARVW>
</E1WYT3M>
</E1LFM1M>
</E1LFA1M>
<E1LFA1M>
<LIFNR>0000641065</LIFNR>
1002
</E1LFA1M>
<E1LFA1M>
<LIFNR>0000641065</LIFNR>
<E1LFM1M>
<EKORG>1004</EKORG>
<E1WYT3M>
<PARVW>BA</PARVW>
</E1WYT3M>
<E1WYT3M>
<PARVW>LF</PARVW>
</E1WYT3M>
<E1WYT3M>
<PARVW>RS</PARVW>
</E1WYT3M>
</E1LFM1M>
<E1LFM1M>
<EKORG>1005</EKORG>
<E1WYT3M>
<PARVW>BA</PARVW>
</E1WYT3M>
<E1WYT3M>
<PARVW>LF</PARVW>
</E1WYT3M>
<E1WYT3M>
<PARVW>RS</PARVW>
</E1WYT3M>
</E1LFM1M>
</E1LFA1M>
</IDOC>
</ZCREMAS>
</ns0:IDOC_Test_Mt>
the Target xsd is like below :
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="urn:sap.shoprite.co.za:demo.trans" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:sap.shoprite.co.za:demo.trans" xmlns:p1="urn:sap.shoprite.co.za:bluecube">
<xsd:import namespace="urn:sap.shoprite.co.za:bluecube"/>
<xsd:element name="Vendor_masterTest1" type="p1:Vendor_masterTest"/>
</xsd:schema>
the EKORG Field from source is mapping to Purchase Organisation(field) in target file .
so here when i use one as many and iam mapping EKORG->MAP WITH DEFAULT ->USE ONE AS MANY and as in the above test data if there are multiple E1LFM1M's the first paramter of Use one as many is getting 2 ekorg's in only one context but here i want them to be created on separate context(please have a look at 4th E1LFA1M in the test data to get clear idea.
can any of you help me in this.
regards.
VarmaHi,
Try this.
Source Code:
IDOC
--->E1LFA1M
-->E1LFM1M
--> EKORG = 1000
--> E1WYT3M
--> E1WYT3M
-->E1LFM1M
-->E1LFM1M
--> EKORG = 1001
--> E1WYT3M
--> E1WYT3M
-->E1LFM1M
--> EKORG = 1006
--> E1WYT3M
--> E1WYT3M
Output:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:target xmlns:ns0="http://test">
<Data>
<M>1000</M>
</Data>
<Data>
<M>1000</M>
</Data>
<Data>
<M></M>
</Data>
<Data>
<M>1001</M>
</Data>
<Data>
<M>1001</M>
</Data>
<Data>
<M>1006</M>
</Data>
<Data>
<M>1006</M>
</Data>
</ns0:target>
Use below Mapping:
Use If then Else Function.
1. If condition: E1WYT3M Exists
2. Then pass E1WYT3M
3. Else Pass E1LFM1M with "Map with Default"
Lets Consider Output of this step as "A".
Use One As Many.
First Input: E1LFM1M to exists to Split By Each Value
Second and Third Input will be Out Put of "A" (Above Step).
Lets Consider Out put of this Step as "B"
Use If without Else.
If "B" is true then pass "A" to exists.
Out put of this to Remove context to Target Vendor Master Node. In my sample it will be Node "Data"
Now for Mapping of Field Purch Org/In my case field "M"
Use If without Else.
If "B" is true then Pass "C". Output of this to Split by each value to target.
For C:
Use if then else
if E1WYT3M exists then pass EKORG else pass constant blank.
Hope its clear!!
-Gouri -
SQL functions extract and XMLSequence for a one-to-many (1:N) relationship
I have have the following XML document loaded into a XMLType table. I'd like to retrieve the lineitem id together with the purchaseorder id and report id. How would the query look like? I've tried a lot but this one-to-many relationship is killing me.
Many thanks!
<report id=...>
<purchaseorder id=...>
<lineitems>
<lineitem id=...>...</lineitem>
<lineitem id=...>...</lineitem>
<lineitem id=...>...</lineitem>
</lineitems>
</purchaseorder>
<purchaseorder id=...>
<lineitems>
<lineitem id=...>...</lineitem>
</lineitems>
</purchaseorder>You can easily modify the above query to your needs:
SQL> with qry as (
2 select t.column_value.extract('/report/@id') report_id,
3 t.column_value.extract('/report/purchaseorder') purchaseorder,
4 t.column_value.extract('/report/purchaseorder/lineitems/*') lineitems
5 from table(xmlsequence(xmltype('<document>
6 <chapter>
7 <report id="1">
8 <purchaseorder id="1">
9 <lineitems>
10 <lineitem id="1">Item 11</lineitem>
11 <lineitem id="2">Item 12</lineitem>
12 <lineitem id="3">Item 13</lineitem>
13 </lineitems>
14 </purchaseorder>
15 <purchaseorder id="2">
16 <lineitems>
17 <lineitem id="1">Item 21</lineitem>
18 </lineitems>
19 </purchaseorder>
20 </report>
21 <report id="2">
22 <purchaseorder id="1">
23 <lineitems>
24 <lineitem id="1">Item 31</lineitem>
25 <lineitem id="2">Item 32</lineitem>
26 </lineitems>
27 </purchaseorder>
28 <purchaseorder id="2">
29 <lineitems>
30 <lineitem id="1">Item 41</lineitem>
31 <lineitem id="2">Item 42</lineitem>
32 </lineitems>
33 </purchaseorder>
34 </report>
35 </chapter>
36 </document>'
37 ).extract('/document/chapter/*'))) t)
38 select q.report_id,
39 q1.column_value.extract('/purchaseorder/@id') purchase_id,
40 q2.column_value.extract('/lineitem/@id') lineitem_id,
41 q2.column_value.extract('/lineitem/text()') lineitem
42 from qry q,
43 table(xmlsequence(q.purchaseorder)) q1,
44 table(xmlsequence(q1.extract('/purchaseorder/lineitems/*'))) q2
45 /
REPORT_ID PURCHASE_ID LINEITEM_ID LINEITEM
1 1 1 Item 11
1 1 2 Item 12
1 1 3 Item 13
1 2 1 Item 21
2 1 1 Item 31
2 1 2 Item 32
2 2 1 Item 41
2 2 2 Item 42
8 rows selected.
SQL> -
One-to-many/foreign keys howto
I have a situation where I'm trying to assemble a web of data and not make
JDO mad.
Here's the structure. I load this data in in batches, with an entry being
placed in a load history table (H) to track each batch. Each batch
contains primary (M) records associated with 0..n qualifying records from
one or both of two auxiliary tables (D, L). All liberally salted with
primary and foreign keys for referential integrity, and most of the keys
are compounds, since the "M" identifiers get recycled for each batch load.
Or, in other words, the "M" key is an ID plus an H key.
Here's a map:
H--0..n-->M
__ +--0..n-->D
__ +--0..n-->L
Just to make things even more fun, the primary key of the H table is an
Oracle 8 "DATE" type, which -- unlike ANSI SQL -- is actually a
"TIMESTAMP". Kodo is rendering this as a java.util.Date rather than
java.sql.Date, which is fine, because I need the full millisecond
resolution. Interestingly, when I altered the schema type to "timestamp",
load operations failed because the "column value was too big" according to
Oracle.
Also adding to the enjoyment, the actual order of presentation of data is
that ALL M records come in, then ALL D records and finally ALL L records.
I create my own H when the load starts.
Now ideally, the whole shooting match will be a single pass/fail
transaction, but that's for later.
Right now, I can create the H, no problem and M's no problem. However,
adding the D's and L's fails come commit time:
kodo.util.FatalUserException: Attempt to set column "OFAC_ADDRESS.LOAD_ID"
to two different values: "7/9/04 9:41 AM", "7/9/04 9:41 AM" This can occur
when you fail to set both sides of a two-sided relation between objects,
or when you map different fields to the same column, but you do not keep
the values of these fields in synch.
The granularity of the timestamps printed isn't making life easier, so I
double-checked the D record's actual local value
ADDRESS SERIALIZER A: Fri Jul 09 09:41:58 EDT 2004/Fri Jul 09 09:41:58 EDT
2004
ADDRESS SERIALIZER B: 1089380518179/1089380518179 (getTime())
ADDRESS SERIALIZER C: -1541174818/-1541174818 (hashCode())
I think I need a clearer understanding of what actions cascade here and
what actions require manual help. For M, I did a setH(H) plus a
setHid(H.getId()) and that made it happy. For D's and L's, of course, I
also have to do a setM(M), where, because of the way the data comes in, I
had to lookup the previously-stored M based on the M.id plus H.id.
Now the parent objects contain sets of child objects. In theory, I should
be adding the newly-created children to those sets, but in practice,
setting the parent on the child appears to cause this to happen
automagically, though I still have to manually set the local value of the
foreign key field.
I really need to find a good FM to RT. Online (and in the Kodo docs), I
find a lot about setting up the XML for one-to-many mapping, but the Java
coding side is taken as obvious. Regrettably, few things are obvious to me.
I suppose I should excerpt the schema just for completeness:
<table name="LOAD_HISTORY">
<pk name="SYS_C0036906" column="LOAD_ID"/>
<column name="LIST_TYPE" type="varchar" size="32"/>
<column name="LOADED_BY" type="varchar" size="32"/>
<column name="LOAD_ID" type="date" not-null="true" size="7"/>
<column name="SUNSET_TIME" type="date" size="7"/>
<fk name="FK_LOADHISTORY_LOADEDBY" delete-action="exception"
to-table="OFAC.OFAC_USERS" column="LOADED_BY"/>
</table>
<table name="OFAC_ADDRESS">
<pk name="SYS_C0036904">
<on column="ADDRESS_ID"/>
<on column="LOAD_ID"/>
</pk>
<column name="ADDRESS" type="varchar" size="125"/>
<column name="ADDRESS_ID" type="decimal" not-null="true"
size="22"/>
<column name="CITY" type="varchar" size="64"/>
<column name="COUNTRY" type="varchar" size="64"/>
<column name="ID" type="decimal" size="22"/>
<column name="LOAD_ID" type="date" not-null="true" size="7"/>
<column name="REMARKS" type="varchar" size="300"/>
<fk name="FK_OFACADDRESS_ID" delete-action="exception"
to-table="OFAC.OFAC_MAIN">
<join column="ID" to-column="ID"/>
<join column="LOAD_ID" to-column="LOAD_ID"/>
</fk>
<fk name="FK_OFACADDRESS_LOADID" delete-action="exception"
to-table="OFAC.LOAD_HISTORY" column="LOAD_ID"/>
</table>
<table name="OFAC_ALIAS">
<pk name="SYS_C0036905">
<on column="ALIAS_ID"/>
<on column="LOAD_ID"/>
</pk>
<column name="ALIAS" type="varchar" size="200"/>
<column name="ALIAS_ID" type="decimal" not-null="true"
size="22"/>
<column name="ID" type="decimal" size="22"/>
<column name="LOAD_ID" type="date" not-null="true" size="7"/>
<column name="REMARKS" type="varchar" size="300"/>
<fk name="FK_OFACALIAS_ID" delete-action="exception"
to-table="OFAC.OFAC_MAIN">
<join column="ID" to-column="ID"/>
<join column="LOAD_ID" to-column="LOAD_ID"/>
</fk>
<fk name="FK_OFACALIAS_LOADID" delete-action="exception"
to-table="OFAC.LOAD_HISTORY" column="LOAD_ID"/>
</table>
<table name="OFAC_MAIN">
<pk name="SYS_C0036903">
<on column="ID"/>
<on column="LOAD_ID"/>
</pk>
<column name="ID" type="decimal" not-null="true" size="22"/>
<column name="LOAD_ID" type="date" not-null="true" size="7"/>
<column name="REMARKS" type="varchar" size="300"/>
<fk name="FK_OFACMAIN_LOADID" delete-action="exception"
to-table="OFAC.LOAD_HISTORY" column="LOAD_ID"/>
</table>Hi Greg,
I'm just using the unmodified schema-to-mapping output. The one thing that
might be unusual is that I've broken up related tables into discrete
packages, but I believe all the items in question are in this package.
Here it is:
<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<package name="com.everbank.finance.ofac3.jdo.sdn">
<class name="LoadHistory">
<jdbc-class-map type="base" table="OFAC.LOAD_HISTORY"/>
<jdbc-version-ind type="state-image"/>
<field name="listType">
<jdbc-field-map type="value" column="LIST_TYPE"/>
</field>
<field name="loadId">
<jdbc-field-map type="value" column="LOAD_ID"/>
</field>
<field name="ofacAddress">
<jdbc-field-map type="one-many"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ADDRESS"/>
</field>
<field name="ofacAlias">
<jdbc-field-map type="one-many"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ALIAS"/>
</field>
<field name="ofacMains">
<jdbc-field-map type="one-many"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_MAIN"/>
</field>
<field name="ofacUsers">
<jdbc-field-map type="one-one" column.USER_ID="LOADED_BY"/>
</field>
<field name="runInfoLoadIdents">
<jdbc-field-map type="one-many"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.RUN_INFO_LOAD_ID"/>
</field>
<field name="sunsetTime">
<jdbc-field-map type="value" column="SUNSET_TIME"/>
</field>
</class>
<class name="OfacAddress">
<jdbc-class-map type="base" table="OFAC.OFAC_ADDRESS"/>
<jdbc-version-ind type="state-image"/>
<field name="address">
<jdbc-field-map type="value" column="ADDRESS"/>
</field>
<field name="addressId">
<jdbc-field-map type="value" column="ADDRESS_ID"/>
</field>
<field name="addressMp1">
<jdbc-field-map type="value" column="ADDRESS_MP1"/>
</field>
<field name="addressMp2">
<jdbc-field-map type="value" column="ADDRESS_MP2"/>
</field>
<field name="city">
<jdbc-field-map type="value" column="CITY"/>
</field>
<field name="cityMp1">
<jdbc-field-map type="value" column="CITY_MP1"/>
</field>
<field name="cityMp2">
<jdbc-field-map type="value" column="CITY_MP2"/>
</field>
<field name="country">
<jdbc-field-map type="value" column="COUNTRY"/>
</field>
<field name="countryMp1">
<jdbc-field-map type="value" column="COUNTRY_MP1"/>
</field>
<field name="countryMp2">
<jdbc-field-map type="value" column="COUNTRY_MP2"/>
</field>
<field name="loadHistory">
<jdbc-field-map type="one-one" column.LOAD_ID="LOAD_ID"/>
</field>
<field name="loadId">
<jdbc-field-map type="value" column="LOAD_ID"/>
</field>
<field name="ofacMain">
<jdbc-field-map type="one-one" column.ID="ID"
column.LOAD_ID="LOAD_ID"/>
</field>
<field name="remarks">
<jdbc-field-map type="value" column="REMARKS"/>
</field>
</class>
<class name="OfacAlias">
<jdbc-class-map type="base" table="OFAC.OFAC_ALIAS"/>
<jdbc-version-ind type="state-image"/>
<field name="alias">
<jdbc-field-map type="value" column="ALIAS"/>
</field>
<field name="aliasId">
<jdbc-field-map type="value" column="ALIAS_ID"/>
</field>
<field name="aliasMp1">
<jdbc-field-map type="value" column="ALIAS_MP1"/>
</field>
<field name="aliasMp2">
<jdbc-field-map type="value" column="ALIAS_MP2"/>
</field>
<field name="aliasType">
<jdbc-field-map type="value" column="ALIAS_TYPE"/>
</field>
<field name="loadHistory">
<jdbc-field-map type="one-one" column.LOAD_ID="LOAD_ID"/>
</field>
<field name="loadId">
<jdbc-field-map type="value" column="LOAD_ID"/>
</field>
<field name="ofacMain">
<jdbc-field-map type="one-one" column.ID="ID"
column.LOAD_ID="LOAD_ID"/>
</field>
<field name="remarks">
<jdbc-field-map type="value" column="REMARKS"/>
</field>
</class>
<class name="OfacMain">
<jdbc-class-map type="base" table="OFAC.OFAC_MAIN"/>
<jdbc-version-ind type="state-image"/>
<field name="callSign">
<jdbc-field-map type="value" column="CALL_SIGN"/>
</field>
<field name="callSignMp1">
<jdbc-field-map type="value" column="CALL_SIGN_MP1"/>
</field>
<field name="callSignMp2">
<jdbc-field-map type="value" column="CALL_SIGN_MP2"/>
</field>
<field name="grt">
<jdbc-field-map type="value" column="GRT"/>
</field>
<field name="id">
<jdbc-field-map type="value" column="ID"/>
</field>
<field name="loadHistory">
<jdbc-field-map type="one-one" column.LOAD_ID="LOAD_ID"/>
</field>
<field name="loadId">
<jdbc-field-map type="value" column="LOAD_ID"/>
</field>
<field name="matchInfos">
<jdbc-field-map type="one-many" ref-column.ID="ID"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.MATCH_INFO"/>
</field>
<field name="ofacAddress">
<jdbc-field-map type="one-many" ref-column.ID="ID"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ADDRESS"/>
</field>
<field name="ofacAlias">
<jdbc-field-map type="one-many" ref-column.ID="ID"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ALIAS"/>
</field>
<field name="pName">
<jdbc-field-map type="value" column="P_NAME"/>
</field>
<field name="pNameMp1">
<jdbc-field-map type="value" column="P_NAME_MP1"/>
</field>
<field name="pNameMp2">
<jdbc-field-map type="value" column="P_NAME_MP2"/>
</field>
<field name="program">
<jdbc-field-map type="value" column="PROGRAM"/>
</field>
<field name="remarks">
<jdbc-field-map type="value" column="REMARKS"/>
</field>
<field name="sName">
<jdbc-field-map type="value" column="S_NAME"/>
</field>
<field name="sNameMp1">
<jdbc-field-map type="value" column="S_NAME_MP1"/>
</field>
<field name="sNameMp2">
<jdbc-field-map type="value" column="S_NAME_MP2"/>
</field>
<field name="sdnType">
<jdbc-field-map type="value" column="SDN_TYPE"/>
</field>
<field name="ssn">
<jdbc-field-map type="value" column="SSN"/>
</field>
<field name="title">
<jdbc-field-map type="value" column="TITLE"/>
</field>
<field name="tonnage">
<jdbc-field-map type="value" column="TONNAGE"/>
</field>
<field name="vesselFlag">
<jdbc-field-map type="value" column="VESSEL_FLAG"/>
</field>
<field name="vesselOwner">
<jdbc-field-map type="value" column="VESSEL_OWNER"/>
</field>
<field name="vesselOwnerMp1">
<jdbc-field-map type="value" column="VESSEL_OWNER_MP1"/>
</field>
<field name="vesselOwnerMp2">
<jdbc-field-map type="value" column="VESSEL_OWNER_MP2"/>
</field>
<field name="vesselType">
<jdbc-field-map type="value" column="VESSEL_TYPE"/>
</field>
</class>
</package>
</mapping>
Als, just for giggles, the JDO file
<?xml version="1.0" encoding="UTF-8"?>
<jdo>
<package name="com.everbank.finance.ofac3.jdo.sdn">
<class name="LoadHistory"
objectid-class="com.everbank.finance.ofac3.jdo.LoadHistoryId">
<field name="loadId" primary-key="true"/>
<field name="ofacAddress">
<collection element-type="OfacAddress"/>
<extension vendor-name="kodo" key="inverse-owner"
value="loadHistory"/>
</field>
<field name="ofacAlias">
<collection element-type="OfacAlias"/>
<extension vendor-name="kodo" key="inverse-owner"
value="loadHistory"/>
</field>
<field name="ofacMains">
<collection element-type="OfacMain"/>
<extension vendor-name="kodo" key="inverse-owner"
value="loadHistory"/>
</field>
<field name="runInfoLoadIdents">
<collection
element-type="com.everbank.finance.ofac3.jdo.match.RunInfoLoadIdent"/>
<extension vendor-name="kodo" key="inverse-owner"
value="loadHistory"/>
</field>
</class>
<class name="OfacAddress"
objectid-class="com.everbank.finance.ofac3.jdo.OfacAddressId">
<field name="addressId" primary-key="true"/>
<field name="loadId" primary-key="true"/>
</class>
<class name="OfacAlias"
objectid-class="com.everbank.finance.ofac3.jdo.OfacAliasId">
<field name="aliasId" primary-key="true"/>
<field name="loadId" primary-key="true"/>
</class>
<class name="OfacMain"
objectid-class="com.everbank.finance.ofac3.jdo.OfacMainId">
<field name="id" primary-key="true"/>
<field name="loadId" primary-key="true"/>
<field name="matchInfos">
<collection
element-type="com.everbank.finance.ofac3.jdo.match.MatchInfo"/>
<extension vendor-name="kodo" key="inverse-owner"
value="ofacMain"/>
</field>
<field name="ofacAddress">
<collection element-type="OfacAddress"/>
<extension vendor-name="kodo" key="inverse-owner"
value="ofacMain"/>
</field>
<field name="ofacAlias">
<collection element-type="OfacAlias"/>
<extension vendor-name="kodo" key="inverse-owner"
value="ofacMain"/>
</field>
</class>
</package>
Greg Campbell wrote:
Hi Tim,
Could you send the your mapping information corresponding to the class that
maps to table: OFAC_ADDRESS. In particular, I'm looking for what fields
map to OFAC_ADDRESS.LOAD_ID. This will hopefully give us a hint as to
what's going wrong.
Thanks,
Greg
"Tim Holloway" <[email protected]> wrote in message
news:[email protected]...
I have a situation where I'm trying to assemble a web of data and not make
JDO mad.
<snipped> -
Is it possible that 1 RTF template with 1 xml file produces many PDF files
Hello,
We are using XML publisher with eBS.
As part of it, we've got treatments that generate invoices.
One treatment produces 1 big XML file with many invoices in it.
Currently, this big XML file generates one big PDF file with all the invoices.
I'd like to know if it's possible to keep the big XML file (with many invoices), and instead, generate 1 PDF file per invoice ?
Basically we would like to split the big PDF file into small PDF, one PDF file per invoice .
If it's possible, then, how can we do it ?
I hope my explanation is clear.
Thanks in advance for your help,
OlivierHave you tried the BI publisher bursting feature?
Take a look at this:
http://www.strsoftware.com/wp-content/uploads/2011/09/Oracle-EBS-and-BI-Publisher-Report-Creation-Bursting-and-Delivery.pdf
http://garethroberts.blogspot.com/2008/03/bi-publisher-ebs-bursting-101.html
Thanks,
Bipuser -
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 -
How to change the fetch size for a one-to-many relationship
With Toplink 10.1.3, since using scrollablecursor is a prerequisites for changing the fetchsize on a query (using the setFetchSize), I am wondering if it would be possible to change the fetchsize of the query which is associated to a one-to-many relationship.
So, is this possible? How ?In TopLink 10.1.3 you can set the fetch-size on any query, it has nothing to do with using a ScrollableCursor.
Example:
readQuery.setFetchSize(100);
To set the fetch size on a mapping query use,
mapping.getSelectionQuery().setFetchSize(100);
In 10.1.3 you can only set this in code, not currently through XML or the Mapping Workbench. In 10.1.3.1 you should be able to set the value through XML as well. -
EJB relation One to Many - ClassCastException
Hi !
I created two CMP EJB entity Client and Address. There is a One to Many relation between them.
When I deploy them on JBoss, I have no errors, and the correponding tables are created in the database. The EJB seems to work fine, but when I use a 'relation' method : myAddress.setClient(myClient) for instance. I get a ServerException.
In the log of JBoss there is :
ClassCastException : org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.SetInstanceValue(...)
I think I have a problem in my descriptors or JBoss configuration.
If u have an idea ...
Thxsorry to whack a load of code in but i can't see where the problem is here is my ejb-jar.xml file:
<ejb-jar>
<enterprise-beans>
<entity>
<description>This bean represents a copy item.</description>
<ejb-name>CopyEJB</ejb-name>
<home>com.RemoteCopyHome</home>
<remote>com.RemoteCopy</remote>
<local-home>com.LocalCopyHome</local-home>
<local>com.LocalCopy</local>
<ejb-class>com.CopyBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Copy</abstract-schema-name>
<cmp-field>
<field-name>copyid</field-name>
</cmp-field>
<cmp-field>
<field-name>quality</field-name>
</cmp-field>
<cmp-field>
<field-name>buyinprice</field-name>
</cmp-field>
<cmp-field>
<field-name>selloutprice</field-name>
</cmp-field>
<cmp-field>
<field-name>bookid</field-name>
</cmp-field>
<cmp-field>
<field-name>title</field-name>
</cmp-field>
<cmp-field>
<field-name>genre</field-name>
</cmp-field>
<primkey-field>copyid</primkey-field>
<security-identity>
<description></description>
<use-caller-identity></use-caller-identity>
</security-identity>
</entity>
<entity>
<description>This bean represents a supplier.</description>
<ejb-name>SupplierEJB</ejb-name>
<home>com.RemoteSupplierHome</home>
<remote>com.RemoteSupplier</remote>
<local-home>com.LocalSupplierHome</local-home>
<local>com.LocalSupplier</local>
<ejb-class>com.SupplierBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Supplier</abstract-schema-name>
<cmp-field>
<field-name>supplierid</field-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
</cmp-field>
<cmp-field>
<field-name>address1</field-name>
</cmp-field>
<cmp-field>
<field-name>address2</field-name>
</cmp-field>
<cmp-field>
<field-name>address3</field-name>
</cmp-field>
<cmp-field>
<field-name>address4</field-name>
</cmp-field>
<cmp-field>
<field-name>postcode</field-name>
</cmp-field>
<cmp-field>
<field-name>email</field-name>
</cmp-field>
<cmp-field>
<field-name>telno</field-name>
</cmp-field>
<primkey-field>supplierid</primkey-field>
<security-identity>
<description></description>
<use-caller-identity></use-caller-identity>
</security-identity>
</entity>
<entity>
<description>This bean represents an edition.</description>
<ejb-name>EditionEJB</ejb-name>
<home>com.RemoteEditionHome</home>
<remote>com.RemoteEdition</remote>
<local-home>com.LocalEditionHome</local-home>
<local>com.LocalEdition</local>
<ejb-class>com.EditionBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Edition</abstract-schema-name>
<cmp-field>
<field-name>editionid</field-name>
</cmp-field>
<cmp-field>
<field-name>isbn</field-name>
</cmp-field>
<cmp-field>
<field-name>publisher</field-name>
</cmp-field>
<cmp-field>
<field-name>binding</field-name>
</cmp-field>
<cmp-field>
<field-name>other</field-name>
</cmp-field>
<cmp-field>
<field-name>edition</field-name>
</cmp-field>
<cmp-field>
<field-name>printdate</field-name>
</cmp-field>
<primkey-field>editionid</primkey-field>
<security-identity>
<description></description>
<use-caller-identity></use-caller-identity>
</security-identity>
</entity>
<entity>
<description>This bean represents an author.</description>
<ejb-name>AuthorEJB</ejb-name>
<home>com.RemoteAuthorHome</home>
<remote>com.RemoteAuthor</remote>
<local-home>com.LocalAuthorHome</local-home>
<local>com.LocalAuthor</local>
<ejb-class>com.AuthorBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Author</abstract-schema-name>
<cmp-field>
<field-name>authorid</field-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
</cmp-field>
<primkey-field>authorid</primkey-field>
<security-identity>
<description></description>
<use-caller-identity></use-caller-identity>
</security-identity>
</entity>
<session>
<description>Supplier Function Session Bean</description>
<display-name>SupplierFunctionEJB</display-name>
<ejb-name>SupplierFunctionEJB</ejb-name>
<home>com.SupplierFunctionHome</home>
<remote>com.SupplierFunctionRemote</remote>
<ejb-class>com.SupplierFunctionSBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
<session>
<description>Copy Function Session Bean</description>
<display-name>CopyFunctionEJB</display-name>
<ejb-name>CopyFunctionEJB</ejb-name>
<home>com.CopyFunctionHome</home>
<remote>com.CopyFunctionRemote</remote>
<ejb-class>com.CopyFunctionSBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<relationships>
<ejb-relation>
<ejb-relation-name>Supplier-Copy</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>copy-recievedfrom-supplier</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<cascade-delete></cascade-delete>
<relationship-role-source>
<ejb-name>CopyEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>supplier</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>supplier-has-items</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>SupplierEJB</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
<ejb-relation>
<ejb-relation-name>Edition-Copy</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>edition-has-items</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>EditionEJB</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>copy-is-a-edition</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<cascade-delete></cascade-delete>
<relationship-role-source>
<ejb-name>CopyEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>edition</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
<!--<ejb-relation>
<ejb-relation-name>Author-Copy</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>copy-has-items</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>AuthorEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>copies</cmr-field-name>
<cmr-field-type>java.util.Set</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>copy-has-authors</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<cascade-delete></cascade-delete>
<relationship-role-source>
<ejb-name>CopyEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>authors</cmr-field-name>
<cmr-field-type>java.util.Set</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>-->
</relationships>
<assembly-descriptor>
<security-role>
<description>This role represents everyone who is allowed full access
to the beans.</description>
<role-name>Subscribers</role-name>
</security-role>
<method-permission>
<role-name>Subscribers</role-name>
<method>
<ejb-name>CopyEJB</ejb-name>
<method-name>*</method-name>
</method>
<method>
<ejb-name>SupplierEJB</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
<container-transaction>
<method>
<ejb-name>CopyEJB</ejb-name>
<method-name>*</method-name>
</method>
<method>
<ejb-name>SupplierEJB</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>my session bean code can be found at
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=11&t=006578 -
Newbie: one to many relationship SQL error
Greetings all-
This is probably a slam dunk for you JDO experts. I'm a JDO newbie, working
with an existing schema in MySQL. I have a one to many relationship between
two tables:
Table "company":
Fields:
company_id: int(11) -- primary key
name : varchar(64)
division : varchar(64)
Table "company_products"
Fields:
company_id: int(11) -- foreign key to table company
product_name: varchar(64)
product_description: varchar(64)
So, I created the corresponding classes:
public class Company {
private int companyID;
private String company_name;
private String division;
// Array of CompanyProduct
private ArrayList companyProducts;
// .. methods omitted
public class CompanyProduct {
private int companyID;
private String productName;
private String productDesc;
// Methods omitted
Then I created the "package.jdo" file:
<?xml version="1.0"?>
<jdo>
<package name="com.packexpo.db">
<class name="Company">
<extension vendor-name="tt" key="table" value="company"/>
<extension vendor-name="tt" key="pk-column" value="company_id"/>
<extension vendor-name="tt" key="lock-column" value="none"/>
<extension vendor-name="tt" key="class-column" value="none"/>
<field name="companyID">
<extension vendor-name="tt" key="data-column" value="company_id"/>
</field>
<field name="name">
<extension vendor-name="tt" key="data-column" value="name"/>
<extension vendor-name="tt" key="column-length" value="64"/>
</field>
<field name="division">
<extension vendor-name="tt" key="data-column" value="division"/>
<extension vendor-name="tt" key="column-length" value="64"/>
</field>
<field name="companyProducts">
<collection element-type="com.packexpo.db.CompanyProduct"/>
<extension vendor-name="tt" key="inverse" value="companyID"/>
</field>
</class>
<class name="CompanyProduct">
<extension vendor-name="tt" key="table" value="company_product"/>
<extension vendor-name="tt" key="pk-column" value="company_id"/>
<extension vendor-name="tt" key="lock-column" value="none"/>
<extension vendor-name="tt" key="class-column" value="none"/>
<field name="companyID">
<extension vendor-name="tt" key="data-column" value="company_id"/>
</field>
<field name="productName">
<extension vendor-name="tt" key="data-column" value="product_name"/>
<extension vendor-name="tt" key="column-length" value="64"/>
</field>
<field name="productDesc">
<extension vendor-name="tt" key="data-column"
value="product_description"/>
<extension vendor-name="tt" key="column-length" value="64"/>
</field>
</class>
</package>
</jdo>
Enhancement works fine. I successfully query and retrive Company objects
from the database, but as soon as I try to get the list of CompanyProducts,
I get an SQL Error:
javax.jdo.JDODataStoreException: [SQL=SELECT company.COMPANYPRODUCTSX FROM
company WHERE company.company_id = 82061]
E0610 Error in executeQuery()
E0606 executeQuery() error --
E0701 Error in getResult().
E0708 Command results in error - 1054 Unknown column
'company.COMPANYPRODUCTSX' in 'field list'
NestedThrowables:
com.solarmetric.kodo.impl.jdbc.sql.SQLExceptionWrapper: [SQL=SELECT
company.COMPANYPRODUCTSX FROM company WHERE company.company_id = 82061]
E0610 Error in executeQuery()
E0606 executeQuery() error --
E0701 Error in getResult().
E0708 Command results in error - 1054 Unknown column
'company.COMPANYPRODUCTSX' in 'field list'
I know i have probably set up the package.jdo file incorrectly, but I'm at a
loss for what I did wrong.
Any suggestions?
Thanks!
-MikeHi,
915766 wrote:
I need to write sql for below requirement:
table structure is
serial no LPN
1 4
2 4
3 6
4 6
5 6
6 3
7 3
8 3
9 1
I have to pick distinct 'LPN' like below:That sounds like a job for "GROUP BY lpn".
(any serial no can be picked for the distinct LPN)It looks like you're displaying the lowest serial_no for each lpn. That's easy to do, using the aggregate MIN function.
results needs to be as below:
serial no LPN
1 4
3 6
6 3
9 1
Please suggest with sql.Here's one way:
SELECT MIN (serial_no) AS serial_no
, lpn
FROM table_x
GROUP BY lpn
ORDER BY lpn -- if wanted
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
is there any way to merge data “one to many”?
like I need to create a letter to many recipients, the text body will remain same for all except the name which variable, the probem is that each recipient will have multiple policies.
Example:
Mr. XXX
Policy-------Date of issue-------Date of Maturity
XXX fund----00/00/2014----------00/00/2014
YYY fund----00/00/2014----------00/00/2014
ZZZ fund----00/00/2014----------00/00/2014
please help if this is possible.ID's built-in Data Merge is strictly a 1:1 application. You can set up your records with fields for multiple policies and leaves some blank, though, and Data Merge can remove blank lines (which means any white space or punctuation must be part of the data). You might also be able to do this with XML.
-
One-to-many relationship within one bean
hello all,
Does S1 support a container managed one-to-many relationship to itself?
I used the verifer to verify my DD and the error is reported. (this prototype is migrated from weblogic6.1 and I use the S1 migration tool for the DD generation)
-----------------database schema-----------------
CREATE TABLE t_class_a
c_name VARCHAR2(255),
one_class_a_for_ma2918_id VARCHAR2(32), /* untruncated name: one_class_a_for_many_class_a_id */
object_id VARCHAR2(32) NOT NULL
CREATE UNIQUE INDEX t_class_a_id_PK ON t_class_a ( object_id );
ALTER TABLE t_class_a ADD ( CONSTRAINT t_class_a_id_PK PRIMARY KEY ( object_id ) USING INDEX );
ALTER TABLE t_class_a ADD ( CONSTRAINT FK_0 FOREIGN KEY ( one_class_a_for_ma2918_id ) REFERENCES t_class_a ( object_id ) );
---------------------------ejb-jar.xml------------------
<abstract-schema-name>ClassABean</abstract-schema-name>
<cmp-field>
<field-name>objectId</field-name></cmp-field>
<cmp-field>
<field-name>name</field-name></cmp-field>
<primkey-field>objectId</primkey-field>
<relationships>
<ejb-relation>
<ejb-relation-name>manyClassA_oneClassA</ejb-relation-name>
<ejb-relationship-role>
<description>optional</description>
<ejb-relationship-role-name>OneClassA-in-manyClassA_oneClassA</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>ClassAEJB</ejb-name></relationship-role-source>
<cmr-field>
<cmr-field-name>manyClassAsForOneClassA</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type></cmr-field></ejb-relationship-role>
<ejb-relationship-role>
<description>optional</description>
<ejb-relationship-role-name>ManyClassA-in-manyClassA_oneClassA</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>ClassAEJB</ejb-name></relationship-role-source>
<cmr-field>
<cmr-field-name>oneClassAForManyClassA</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
</relationships>
-----------sun-cmp-mapping.xml--------
<sun-cmp-mapping>
<schema>mySchema</schema>
<entity-mapping>
<ejb-name>ClassAEJB</ejb-name>
<table-name>T_CLASS_A</table-name>
<cmp-field-mapping>
<field-name>objectId</field-name>
<column-name>OBJECT_ID</column-name></cmp-field-mapping>
<cmp-field-mapping>
<field-name>name</field-name>
<column-name>C_NAME</column-name></cmp-field-mapping>
<cmr-field-mapping>
<cmr-field-name>manyClassAsForOneClassA</cmr-field-name>
<column-pair>
<column-name>T_CLASS_A.OBJECT_ID</column-name>
<column-name>T_CLASS_A.ONE_CLASS_A_FOR_MA2918_ID</column-name></column-pair></cmr-field-mapping></entity-mapping></sun-cmp-mapping></sun-cmp-mappings>
I beleive the migration tool missing the cmr-filed mapping for the oneClassAForManyClassA relation role.
but even if I add this mapping it still can't pass the verifiy.
So do I miss any thing or I can conclude S1 not support this one-to many self relation?
Any hint would be welcome.It does.
There is a known problem with parsing self-referenced relationship info - the one side (with <multiplicity> Many) must be the first in the <ejb-relation> entry.
Regards,
Marina -
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
Maybe you are looking for
-
My i phone 4s is taking long time to charge?
Everything has been fine for the last few days but all of a sudden it will not charge. I have had it on for the last few hours and it is still on 5/6%?
-
Dear Experts , I want to convert my XML file to the ABAP Internal table. For this I have to Setuo a XSLT transformation. My XML File is as follows : <!--XML Export from Broadcast Master List.--> <!--Seg Codes List, Created 02/02/2010 16:02--> <?xml v
-
How to print directly from Windows7 desktop on Officejet 5745 without emailing the printer
Successfully installed HP 5745 and set up eprint on Dell Ispiron 3847 running Windows 7 Professional. How do you print a document or email on desktop directly from the printer without emailing it to the printer's email? Prior Windows XP printing by
-
No icon after 11.2.0.115 update
Installed the iTunes for Windows 64 update 11.2.0.115 and now have no icon for my shortcut or the program. Reinstalled to repair. No change.
-
Using Mac Snow leopard and Lightroom 3.4.1 and when trying to edit in Elements the Elements edit app opens but the file does not appear. To edit I have to open file/open and navigate to the file? Alan