James Sutherland

Ranch Hand
+ Follow
since Oct 01, 2007
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by James Sutherland

I would start by getting an SQL log of what is really occurring (log level to FINE if using EclipseLink).

If you are deleting a lot of the same types of objects, batch writing may help.


Otherwise, if you are deleting a dependency tree you could try CASCADE DELETE on the database.


EclipseLink also has a @DeleteAll optimization for private OneToMany relationships.

If you are deleting a large batch of objects, you could use a JPQL bulk delete,

You don't need to do anything special, just map it the same way you map any relationship. You can use @OneToOne or @ManyToOne.

How about,


Of coarse if the Department was already in the cache, the find on it and access to its employees would be the most efficient way to access the employees.
If they both have a relationship to each other, then they have a bi-directional relationship.

You need to call persist on both the parent and the child, or set cascade persist in the OneToMany.

I assume you want to insert another child of the same parent.

Since the parent is existing, you should first find() the existing parent, then create a new Child with that parent and persist it.

If you are dealing with a detached child (serialize from remote), then you can call merge() instead of persist, and JPA should figure out it is new and the parent is existing (assuming the id is set in the parent).
The first error seemed to be related to your code being compiled with JPA 2.0, but your runtime using TopLink Essentials that only support JPA 1.0.
Consider upgrading to EclipseLink (TopLink 11g).

Your second error seemed to occur because you have not packaged or deployed your application correctly. Ensure you list your classes in the persistence.xml, and that they are annotated with @Entity.

In your code you call createEmployee with an Employee but your code takes String, String, ..., so what you posted is not the real code.
Your createEmployee seems to be creating a new Employee, so make sure you are adding the photos to that employee.

Also, your addPhotos method first does a contains, ensure that your equals and hashCode methods are correct.
Looks like you did not assign the address to the student, and have a not null constraint in your table disallowing this.

What is your code for the persist?
Are you sure you are setting the balance? Include your code and the log on finest.
What is the error? (and the code that the error occurs in)
You can persist the same JAXB generated class through JPA by adding @Entity and @Id annotations to them.
You can auto create a database schema using DDL generation in your JPA persistence.xml,



Normally it is better to design an object mode, then map it to XML and the database using JAXB and JPA annotations.
What error/issue do you get?

Ensure the Produto class is listed in your persistence.xml.

Try enabling logging on finest to debug issues.
Reading the object, then updating it is normally the best way to update an object, and ensure correct versioning/locking, caching and consistency.

You can also issue a direct update in JPQL using an UPDATE query,

See, http://en.wikibooks.org/wiki/Java_Persistence/Querying#Update_and_Delete_Queries