[Management, JMX/JBoss] - Interacting with the LoaderRepository MBean
by miclopezalv
greetings,
i'm having a big problem with my application, because it has to be changing classes in a dynamic way, for example, the server is up and running, and someone creates a new .java archive, so, the app. has to compile it, and add it to the classpath, making it available for other module to use it. I was trying using custom class loaders, but it doesn´t work because of the problems that usually arise when using different class loaders inside the AS (ClassCastException, LinkageException, etc.).
Seen all this problems, i saw a posible solution in the UnifiedLoaderRepository, so my application can use the Repository that the server is actually using and load the classes it needs. the question is: this kind of thing can be made?
how do i interact with the repository from a regular class, or and ejb3 session bean packaged in a regular .jar.?
I`m trying using something like:
MBeanServer server = MBeanServerLocator.locate();
try{
ObjectName objectName = new ObjectName("org.jboss.mx.loading:name=Default");
UnifiedLoaderRepository3MBean mbean = (UnifiedLoaderRepository3MBean)MBeanServerInvocationHandler.newProxyInstance(
server,
objectName, UnifiedLoaderRepository3MBean.class,
false);
System.out.println("obtaining class info: "+mbean.displayClassInfo("com.its.connection.ConnectionSetting"));
}catch(Exception e){
e.printStackTrace();
}
any help mould be appreciated.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3972313#3972313
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3972313
19 years, 7 months
[EJB 3.0] - Cannot remove entites used in relationships
by andydale
Hi,
I have set up a very simple entity model to test relationships in EJB3. I have no problems in adding to them, and removing an entity so long as it is not used in a relationship (not refered to as a foriegn key value).
The problem occurs when trying to remove the entity when it is used in a relationship be it many to many or many to one/one to many. Another thing to note about the relationships between the entites is that on the owning side a java.util.Set is used and on the non-owning side a java.util.Collection is used. To give an example of a this in a many to many context.
I have 3 Entities Student, Course, and Institution and all of these relationships are many to many (please see below).
In Student.java the student-course many to many and collection declaration
| private Collection<Course> mCourses = new ArrayList<Course>();
|
| @ManyToMany(mappedBy = "students", fetch = FetchType.EAGER, cascade ={CascadeType.PERSIST, CascadeType.MERGE})
| public Collection<Course> getCourses() {
| return mCourses;
| }
|
in Course.java student-course many to many and collection declarations/b]
| private Set<Student> mEnrolledStudents = new HashSet<Student>();
|
| @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
| @JoinTable(name = "course_student",
| joinColumns = @JoinColumn(name = "course_id", referencedColumnName = "course_id"),
| inverseJoinColumns = @JoinColumn(name = "student_id", referencedColumnName = "student_id"))
| public Set<Student> getStudents() {
| return mEnrolledStudents;
| }
in Course.java course-institution many to many and collection declaration
| private Collection<Institution> mInstitutionsRunningCourse = new ArrayList<Institution>();
|
| @ManyToMany(mappedBy = "courses", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
| public Collection<Institution> getInstitutions() {
| return mInstitutionsRunningCourse;
| }
in Institution.java course-institution many to many
| private Set<Course> mCoursesOffered = new HashSet<Course>();
|
| @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
| @JoinTable(name = "institution_course",
| joinColumns = @JoinColumn(name = "institution", referencedColumnName = "institution_id") ,
| inverseJoinColumns = @JoinColumn(name = "course", referencedColumnName = "course_id") )
| public Set<Course> getCourses() {
| return mCoursesOffered;
| }
I create a course with 3 students on it (3 entries in the association table) and also link this course to 2 institutions (2 entries in the association table). Then i try to call the EntityManager.remove() method from within the same SLSB. The error i get is this
anonymous wrote : Caused by: java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=dale.comsoft.de/50, BranchQual=, localId=50] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.EntityNotFoundException: org.hibernate.ObjectDeletedException: deleted entity passed to persist: [test.Course#])
| at org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:198)
| at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:180)
| at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
| at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:181)
| at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
| at $Proxy347.tryDelete(Unknown Source)
| at test.TestRelationships.storeData(TestRelationships.java:63)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
| ... 29 more
| Caused by: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=dale.comsoft.de/50, BranchQual=, localId=50] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.EntityNotFoundException: org.hibernate.ObjectDeletedException: deleted entity passed to persist: [test.Course#])
| at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:372)
| at org.jboss.tm.TxManager.commit(TxManager.java:240)
| at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
| ... 51 more
| Caused by: javax.persistence.EntityNotFoundException: org.hibernate.ObjectDeletedException: deleted entity passed to persist: [test.Course#]
| at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:564)
| at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:484)
| at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
| at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
| at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
| ... 53 more
| Caused by: org.hibernate.ObjectDeletedException: deleted entity passed to persist: [test.Course#]
| at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:90)
| at org.hibernate.impl.SessionImpl.firePersistOnFlush(SessionImpl.java:646)
| at org.hibernate.impl.SessionImpl.persistOnFlush(SessionImpl.java:638)
| at org.hibernate.engine.CascadingAction$9.cascade(CascadingAction.java:225)
| at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
| at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
| at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
| at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
| at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
| at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
| at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
| at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
| at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:130)
| at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:121)
| at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
| at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
| at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
| at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
| at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:475)
| ... 56 more
I cannot figure out what is wrong, I even tried to clear the set and collection first thus leaving the database in the correct state (tested it by just calling persist and not remove) then removing the entity and i still get the same error.
I have also tried annotating with this :
| @org.hibernate.annotations.Cascade( {
| org.hibernate.annotations.CascadeType.ALL,
| org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
|
but that does not work.
Can anyone shed any light on where i have gone wrong ?
Thanks in advance,
Andy
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3972305#3972305
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3972305
19 years, 7 months
[JBossCache] - Re: Hibernate/Cache conceptual mismatch
by otaylor
Wanted to pick up this old thread and add a few observations I've made:
EHCache and similar are working on an entirely different code path ... the CacheConcurrencyStrategy is ReadWriteCache rather than TransactionalCache; ReadWriteCache is a pretty complex scheme, but the basic idea of it is that it stores lock objects in the cache that wrap the actual cached objects and keeps lock state and timestamps in the lock objects.
AFAIK the two TreeCache based caches are the only users of TransactionalCache.
Yes, the fail-fast variant of put is used currently. Issues that I'm aware of with it:
- It doesn't work with optimistic locking (just broken? doesn't make senes? not sure)
- It doesn't replicate quite properly (the "fail-silently" option isn't replicated)
- It isn't handled for INVALIDATE_SYNC at all right (The 0-timeout isn't propagate)
- It's not 100% correct
To expand on the last, the problem is that you can have:
a) get() returns null
b) new data or delete comimtted in database and cache
c) put() overwrites the newer data
I'd argue that get() needs to establish a hard read lock (even when the node isn't there, even if the isolation mode is READ_COMMITTED) that is upgraded to a write lock on put() and then released/downgraded afterwards. (Doing the get()/put() pair in their own transaction might make sense, just as the fail-fast put is done in its own transaction now)
This would likely require some Hibernate <=> cache changes to make sure that a failed get() is always followed by another call (a put() on success, but the item might not have been in the database, or there could have been other failures.)
The above is of course somewhat similar to what the cache loader infrastructure does, but wedging into that would be more invasive on the Hibernate side.
Anyways, I don't want to go into a lot more detail here, but just wanted to point out that dealing only with the put() and not considering the get()/put() cycle has some issues.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3972304#3972304
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3972304
19 years, 7 months