[
http://opencast.jira.com/browse/MH-8819?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=32588#comment-32588
]
Lukas Rohner edited comment on MH-8819 at 12/12/12 8:47 AM:
------------------------------------------------------------
Hi I wasn't able to create a review, because crucible seems not to be working
at the moment. So I will write it here. I saw it by random and would like to
share. Tobias you created a named query to update the entity, this works but
with JPA it's not meant to do it by your self. All the update magic is done by
JPA itself. There are a lot of examples in the existing code how to work with
JPA (SearchServiceDatabaseImpl, SeriesServiceDatabaseImpl, ...) maybe have a
look at these classes too.
Done by named query: (there is also no NotFoundException thrown)
public Annotation changeAnnotation(Annotation a) throws NotFoundException {
EntityTransaction tx = null;
EntityManager em = null;
AnnotationImpl b = null;
long id = a.getAnnotationId();
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
Query q = em.createNamedQuery("updateAnnotation");
q.setParameter("value", a.getValue());
q.setParameter("annotationId", id);
int no = q.executeUpdate();
if (no == 1) {
b = em.find(AnnotationImpl.class, id);
}
tx.commit();
return b;
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
}
Done by JPA.
public Annotation changeAnnotation(Annotation a) throws NotFoundException {
EntityTransaction tx = null;
EntityManager em = null;
long id = a.getAnnotationId();
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
AnnotationImpl b = em.find(AnnotationImpl.class, id);
if(b == null)
throw new NotFoundException();
b.setAnnotationId(a.getAnnotationId());
....
.... // update the entity by setters
...
b.setCreated(a.getCreated());
em.merge(b); // then merge it
tx.commit();
return b;
} finally {
if (tx.isActive()) {
tx.rollback();
}
if (em != null) // possible null pointer!
em.close();
}
}
was (Author: lrohner):
Hi I wasn't able to create a review, because crucible seems not to be
working at the moment. So I will write it here. I saw it by random and would
like to share. Tobias you created a named query to update the entity, this
works but with JPA it's not meant to do it by your self. All the update magic
is done by JPA itself.
Done by named query: (there is also no NotFoundException thrown)
public Annotation changeAnnotation(Annotation a) throws NotFoundException {
EntityTransaction tx = null;
EntityManager em = null;
AnnotationImpl b = null;
long id = a.getAnnotationId();
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
Query q = em.createNamedQuery("updateAnnotation");
q.setParameter("value", a.getValue());
q.setParameter("annotationId", id);
int no = q.executeUpdate();
if (no == 1) {
b = em.find(AnnotationImpl.class, id);
}
tx.commit();
return b;
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
}
Done by JPA.
public Annotation changeAnnotation(Annotation a) throws NotFoundException {
EntityTransaction tx = null;
EntityManager em = null;
long id = a.getAnnotationId();
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
AnnotationImpl b = em.find(AnnotationImpl.class, id);
if(b == null)
throw new NotFoundException();
b.setAnnotationId(a.getAnnotationId());
....
.... // update the entity by setters
...
b.setCreated(a.getCreated());
em.merge(b); // then merge it
tx.commit();
return b;
} finally {
if (tx.isActive()) {
tx.rollback();
}
if (em != null) // possible null pointer!
em.close();
}
}
> Annotation service: Annotations can't be changed
> ------------------------------------------------
>
> Key: MH-8819
> URL: http://opencast.jira.com/browse/MH-8819
> Project: Matterhorn Project
> Issue Type: Bug
> Components: Architecture & Services
> Affects Versions: 1.3
> Reporter: Martin Abel
> Assignee: Tobias Schiebeck
> Fix For: Trunk, 1.4
>
>
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
http://opencast.jira.com/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
Matterhorn mailing list
[email protected]
http://lists.opencastproject.org/mailman/listinfo/matterhorn
To unsubscribe please email
[email protected]
_______________________________________________