Welcome Guest  |  Register  |  Login
Login Name Password
  Search  
  Index  | Recent Threads  | Unanswered Threads  | Who's Online  | Help


Quick Go »

No member browsing this thread
Thread Status: Active
Total posts in this thread: 12
Posts: 12   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 4313 times and has 11 replies Next Thread
Male TBR
Newbie




Joined: Apr 24, 2009
Post Count: 3
Status: Offline
Reply to this Post  Reply with Quote 
How persist in a new empty XML Datastore ?


I somebody !

I am trying to persist in a new empty (non-existing) XML datastore and I get the exception :


Exception in thread "main" java.lang.IllegalArgumentException
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:295)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:272)
at org.datanucleus.store.xml.binder.JAXBRuntimeBinder.unmarshall(JAXBRuntimeBinder.java:137)
at org.datanucleus.store.xml.fieldmanager.FetchFieldManager.<init>(FetchFieldManager.java:65)
at org.datanucleus.store.xml.XMLPersistenceHandler.fetchObject(XMLPersistenceHandler.java:361)
at org.datanucleus.state.JDOStateManagerImpl.validate(JDOStateManagerImpl.java:4175)
at org.datanucleus.ObjectManagerImpl.findObject(ObjectManagerImpl.java:2449)
at org.datanucleus.ObjectManagerImpl.exists(ObjectManagerImpl.java:1943)
at org.datanucleus.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:362)
at datanucleous.xa.Replication.main(Replication.java:66)


At first glance it seems to be a JAXB 2.1 issue ... my persistence.xml file is :

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="datanucleus-poc"
transaction-type="RESOURCE_LOCAL">
<provider>org.datanucleus.jpa.PersistenceProviderImpl</provider>
<class>datanucleous.xa.Product</class>
<properties>
<property name="datanucleus.ConnectionDriverName"
value="com.mysql.jdbc.Driver" />
<property name="datanucleus.ConnectionURL"
value="jdbc:mysql://localhost:3306/jpa" />
<property name="datanucleus.ConnectionUserName" value="jpa" />
<property name="datanucleus.ConnectionPassword" value="jpa" />
<property name="datanucleus.identifier.case" value="LowerCase" />
<property name="datanucleus.autoCreateSchema" value="true" />
</properties>
</persistence-unit>
<persistence-unit name="datanucleus-poc-xml"
transaction-type="RESOURCE_LOCAL">
<provider>org.datanucleus.jpa.PersistenceProviderImpl</provider>
<class>datanucleous.xa.Product</class>
<properties>
<property name="datanucleus.ConnectionURL"
value="xml:file:myfile.xml" />
<property name="datanucleus.autoStartMechanism"
value="Classes" />
<property name="datanucleus.autoStartClassNames"
value="datanucleous.xa.Product" />
</properties>
</persistence-unit>
</persistence>



Note there are 2 persistence units : source then target. I am trying to do something like replicate tables from one RDBMS Datastore to an XML Datastore ...


/**
*
*/
package datanucleous.xa;

import java.util.Iterator;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;

import org.datanucleus.jpa.JPAReplicationManager;

public class Replication {

private EntityManager em1;

private EntityTransaction etx1;

private EntityManagerFactory emf1;

private EntityManager em2;

private EntityTransaction etx2;

private EntityManagerFactory emf2;

public static void main(String[] args) {
Replication r = new Replication();


r.emf1 = Persistence
.createEntityManagerFactory("datanucleus-poc");
r.emf2 = Persistence
.createEntityManagerFactory("datanucleus-poc-xml");

r.em1 = r.emf1.createEntityManager();
r.etx1 = r.em1.getTransaction();
r.etx1.begin();

Product p0 = new Product("a","b",9.0);
r.em1.persist(p0);

r.em1.flush();

Query q = r.em1.createNamedQuery("datanucleous.xa.Product.selectProducts");
q.setParameter("higherPrice", Double.MAX_VALUE);
List l = q.getResultList();

r.etx1.commit();
r.em1.close();

r.em2 = r.emf2.createEntityManager();
r.etx2 = r.em2.getTransaction();
r.etx2.begin();

for (Iterator iter = l.iterator(); iter.hasNext();) {
Product p = (Product) iter.next();
r.em2.persist(p);
}

r.etx2.commit();
r.em2.close();

r.emf1.close();
r.emf2.close();

}
}


The "myfile.xml" is created from scratch but is empty (even no header). When the first "persist" attempt occurs I suppose it fails because of empty file.

My question is : is there a way to previously create the schema or initialize this target XML file ?

thanks.

[Apr 25, 2009 12:50:45 AM] Show Printable Version of Post    View Member Profile    Send Private Message    Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male andy
Expert
Member's Avatar

UK
Joined: Mar 13, 2004
Post Count: 5686
Status: Offline
Reply to this Post  Reply with Quote 
Re: How persist in a new empty XML Datastore ?

1. Mentioning the class that you're persisting cos it may have something to do with it wink.
2. Why not start with no XML file ? that's the situation we use in our tests. Schema elements are added when an object is persisted.
3. Why not just build up from persisting a new object into XML (omit the RDBMS part for now) ?
4. You don't need "auto-start" in the XML store; you already specified the class in your persistence-unit.
----------------------------------------
-Andy smile

[Apr 25, 2009 6:03:36 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male erik
Expert
Member's Avatar

Belgium
Joined: Mar 12, 2004
Post Count: 2991
Status: Offline
Reply to this Post  Reply with Quote 
Re: How persist in a new empty XML Datastore ?

you can raise a bug. the node is null and should a NucleusObjectNotFoundException
----------------------------------------
Erik Bengtson


[Apr 25, 2009 10:18:13 AM] Show Printable Version of Post    View Member Profile    Send Private Message    Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male erik
Expert
Member's Avatar

Belgium
Joined: Mar 12, 2004
Post Count: 2991
Status: Offline
Reply to this Post  Reply with Quote 
Re: How persist in a new empty XML Datastore ?

issue created http://www.jpox.org/servlet/jira/browse/NUCXML-31
----------------------------------------
Erik Bengtson


[Apr 25, 2009 11:50:16 AM] Show Printable Version of Post    View Member Profile    Send Private Message    Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male TBR
Newbie




Joined: Apr 24, 2009
Post Count: 3
Status: Offline
Reply to this Post  Reply with Quote 
Re: How persist in a new empty XML Datastore ?

I Andy & Erik, thanks for your answers and guidelines.

1. Mentioning the class that you're persisting cos it may have something to do with it.

sorry Andy, you are right, see the Entity bean below ...
please note I tried to persist alternatively into xml and excel datastore (using @Extension) and, strangely, I have got the same kind of problem with excel datastore (changing file URL to excel:file:myfile.xls). It suggest me I forget something important about schema initialization... but what ?

package datanucleous.xa;

import javax.persistence.*;

import org.datanucleus.jpa.annotations.Extension;
import org.datanucleus.jpa.annotations.Extensions;

@Extensions({
@Extension(vendorName = "datanucleus", key = "xpath", value = "/product"),
@Extension(vendorName = "datanucleus", key = "sheet", value = "product")
}
)
@Entity
@NamedQueries( { @NamedQuery(name = "datanucleous.xa.Product.selectProducts", query = "SELECT p FROM Product p WHERE p.price < :higherPrice") })
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@TableGenerator(
name = "PRODUCT_GENERATOR",
table = "PRODUCT_SEQUENCE",
pkColumnName = "PRODUCT_PK",
valueColumnName = "PRODUCT_VALUE",
pkColumnValue = "PRODUCT_ID",
allocationSize = 10)
public class Product {
/**
*
* id: long
**/
@Extensions({
@Extension(vendorName = "datanucleus", key = "XmlAttribute", value = "true"),
@Extension(vendorName = "datanucleus", key = "index", value = "0")
}
)
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "PRODUCT_GENERATOR")
private String id;

/**
*
* name: String
**/
@Extensions({
@Extension(vendorName = "datanucleus", key = "XmlElement", value = "true"),
@Extension(vendorName = "datanucleus", key = "index", value = "1")
}
)
private String name;

/**
*
* description: String
**/
@Extensions({
@Extension(vendorName = "datanucleus", key = "XmlElement", value = "true"),
@Extension(vendorName = "datanucleus", key = "index", value = "2")
}
)
private String description;

/**
*
* price: Double
**/
@Extensions({
@Extension(vendorName = "datanucleus", key = "XmlElement", value = "true"),
@Extension(vendorName = "datanucleus", key = "index", value = "3")
}
)
private Double price;

/**
*
* @param name :
* @param description :
* @param price :
**/
public Product(String name, String description, Double price) {
this.name = name;
this.description = description;
this.price = price;
}

/**
*
**/
public Product() {
super();
}

/**
* Return value of attribute id
*
* @return <code>long</code> :
**/
public String getId() {
return this.id;
}

/**
* Set value of attribute id
*
* @param id : the new value of id
**/
public void setId(String id) {
this.id = id;
}

/**
* Return value of attribute name
*
* @return <code>String</code> :
**/
public String getName() {
return this.name;
}

/**
* Set value of attribute name
*
* @param name : the new value of name
**/
public void setName(String name) {
this.name = name;
}

/**
* Return value of attribute description
*
* @return <code>String</code> :
**/
public String getDescription() {
return this.description;
}

/**
* Set value of attribute description
*
* @param description : the new value of description
**/
public void setDescription(String description) {
this.description = description;
}

/**
* Return value of attribute price
*
* @return <code>Double</code> :
**/
public Double getPrice() {
return this.price;
}

/**
* Set value of attribute price
*
* @param price : the new value of price
**/
public void setPrice(Double price) {
this.price = price;
}


@Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((id == null) ? 0 : id.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
final Product other = (Product) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}


2. Why not start with no XML file ? that's the situation we use in our tests. Schema elements are added when an object is persisted.

Launching with an empty xml file or launching with NO file (let datanucleus process create it) has the same effect.

3. Why not just build up from persisting a new object into XML (omit the RDBMS part for now) ?

My goal was initially to test copy from one datastore to an other using the same Entity Bean !

Following your advice I omitted the RDBMS part and it works fine now !
But, obviously, I had to comment the @TableGenerator/@GeneratedValue annotations, which are not supported in XML datastore context, and set "id" manually to succeed.

Nevertheless I think an Entity Bean should be usable without any changes accross multiple datastores of different types. It seems not be possible.

Actually, I think that is the reason why my full use case doesn't work.

What do you think about ?
[Apr 25, 2009 11:47:58 PM] Show Printable Version of Post    View Member Profile    Send Private Message    Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male andy
Expert
Member's Avatar

UK
Joined: Mar 13, 2004
Post Count: 5686
Status: Offline
Reply to this Post  Reply with Quote 
Re: How persist in a new empty XML Datastore ?

Well JDO is actually the spec that was designed to work with multiple datastores and to allow such things, and it does allow that (e.g package-mysql.orm, package-xml.orm). JPA was not designed for this. That said, DataNucleus would allow you to have persistence-unit 1 for RDBMS with an orm.xml at a particular place in the CLASSPATH, and then have persistence-unit 2 for XML at a different place in the CLASSPATH, and in these orm.xml files you could put value-generation for RDBMS, and not for XML. You cannot expect to put such datastore-specific info in annotations and things to just work

If you used JDO (or with JPA, doing as I said above) you could do what you want to do (value generation in MySQL, and just use the id as specified by the user in XML). In fact you can see this exact idea in use in our test suite
http://datanucleus.svn.sourceforge.net/viewvc...trunk/test.jdo.replicate/
where we have a convenience JDOReplicationManager and replicate RDBMS to XML, and vice-versa.
----------------------------------------
-Andy smile

[Apr 26, 2009 6:19:28 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male TBR
Newbie




Joined: Apr 24, 2009
Post Count: 3
Status: Offline
Reply to this Post  Reply with Quote 
Re: How persist in a new empty XML Datastore ?

Thank you again Andy. You really help me to get a good overview of Datanuleus. I achieved my goal with success. I will continue to explore it ...

Just a question : using the following code (to copy my RDBMS datastore to an XML datastore) ...

JPAReplicationManager replicator = new JPAReplicationManager(r.emf1, r.emf2);
replicator.replicate(new Class[]{datanucleous.xa.ProductForFullReplication.class});

... I encountered the exception ...


Exception in thread "main" java.lang.IllegalArgumentException: Type ("[Ljava.lang.Object;") is not that of an entity but needs to be for this operation
at org.datanucleus.jpa.EntityManagerImpl.assertEntity(EntityManagerImpl.java:820)
at org.datanucleus.jpa.EntityManagerImpl.merge(EntityManagerImpl.java:397)
at org.datanucleus.jpa.JPAReplicationManager.replicateInTarget(JPAReplicationManager.java:305)
at org.datanucleus.jpa.JPAReplicationManager.replicate(JPAReplicationManager.java:165)
at datanucleous.xa.Replication.main(Replication.java:68)
Caused by: org.datanucleus.exceptions.ClassNotPersistableException: The class "[Ljava.lang.Object;" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
at org.datanucleus.ObjectManagerImpl.assertClassPersistable(ObjectManagerImpl.java:3871)
at org.datanucleus.jpa.EntityManagerImpl.assertEntity(EntityManagerImpl.java:816)
... 4 more


I succeed to copy my RDBMS datastore by other ways but I failed using the dedicated JPAReplicationManager.

For me it sounds like a bug ... Is it a known bug (or a known clumsiness from newbies smile ) ? I didn't find anything about on forum nor Jira. Do you want I build a test case respectful to your rules as described on "Problem Reporting" page ?

bye

TBR
[May 1, 2009 11:51:31 PM] Show Printable Version of Post    View Member Profile    Send Private Message    Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male cimballi
Newbie



Peru
Joined: Jan 30, 2010
Post Count: 5
Status: Offline
Reply to this Post  Reply with Quote 
Re: How persist in a new empty XML Datastore ?

Hi,

I am new to Datanucleus, I am doing some tests with the XML datastore and I am facing the same problem as TBR with a 2.0.0 version.
The error happens when I try to read an entity from the store, and at the time I do that the XML datastore contains only one entity from a different type.

I am using Spring JdOTemplate but I don't think it has any impact. The beginning of the stack trace is :

java.lang.IllegalArgumentException
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:295)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:272)
at org.datanucleus.store.xml.binder.JAXBRuntimeBinder.unmarshall(JAXBRuntimeBinder.java:137)
at org.datanucleus.store.xml.fieldmanager.FetchFieldManager.<init>(FetchFieldManager.java:66)
at org.datanucleus.store.xml.XMLPersistenceHandler.fetchObject(XMLPersistenceHandler.java:368)
at org.datanucleus.state.JDOStateManagerImpl.loadFieldsFromDatastore(JDOStateManagerImpl.java:1912)


Thanks for your help,

Cimballi
[Jan 30, 2010 6:02:21 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male andy
Expert
Member's Avatar

UK
Joined: Mar 13, 2004
Post Count: 5686
Status: Offline
Reply to this Post  Reply with Quote 
Re: How persist in a new empty XML Datastore ?

Hi, The forum posting guide is very clear; demonstrate a problem using valid DataNucleus testcase defined at
http://www.datanucleus.org/project/problem_reporting.html
The previous poster didn't do that either, and without it we just don't have the time
----------------------------------------
-Andy smile

----------------------------------------
[Edit 1 times, last edit by andy at Jan 30, 2010 12:50:22 PM]
[Jan 30, 2010 11:54:57 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male cimballi
Newbie



Peru
Joined: Jan 30, 2010
Post Count: 5
Status: Offline
Reply to this Post  Reply with Quote 
Re: How persist in a new empty XML Datastore ?

Hi Andy,

Sure, I didn't took time the read the recommandations...

On another side I explored my problem and I can give you more informations. The problem appears on this code :
super.getJdoTemplate().getObjectById(this.entityClass, entityId);

For sure, the entity associated to this id doesn't exist in the repository, but the problem is that it is raising an IllegalArgumentException.

It seems the root of the pb is in org.datanucleus.store.xml.XMLUtils, the findNode method, line 244 :
node = (Node) xpath.evaluate(expression, doc, XPathConstants.NODE);

Here, as the node doesn't exist, the evaluation returns null, and later the null value is passed to JaxB which generates an IllegalArgumentException. I am not sure but maybe there should be a test for a null value and then throws a NucleusObjectNotFoundException like for the post of the other user, but it was a different case.

Appart from that, there is something I don't undertand, it seems that the default JDO behavior is to throw an exception when calling getObjectById and the object doesn't exist. But so, is there a simple way to test if an ID is already in use or not ? For example, a mehod which returns a boolean or null.

Thanks,

Cimballi
[Jan 30, 2010 4:14:24 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Posts: 12   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread