James Sutherland

Ranch Hand
+ Follow
since Oct 01, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

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.

http://java-persistence-performance.blogspot.com/2013/05/batch-writing-and-dynamic-vs.html

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

See,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/DeleteCascade

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,

http://en.wikibooks.org/wiki/Java_Persistence/JPQL#Delete_Queries
You don't need to do anything special, just map it the same way you map any relationship. You can use @OneToOne or @ManyToOne.

http://en.wikibooks.org/wiki/Java_Persistence/Inheritance
How about,



or,



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.

i.e.
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,

see,

http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/p_ddl_generation.htm#BABHEJJI

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