[EJB 3.0] - Re: Eager fetching missing an element when retrieved remotel
by Bigdaddy
Wow, I almost forgot about this.
I still do not know what the problem is with this implementation of @ManyToMany. Actually, I do not believe anything is wrong with the code as written. I am fairly certain there is a problem with Hibernate, the entity manager, data marshaller, or something else. I would welcome someone to point out a mistake that I may have made.
Anyhow, for those interested there is a workaround. Create the relational entities (i.e. ParentChildTbl and ChildGrandchildTbl) yourself and apply @ManyToOne, @OneToMany annotations with Sets-- not Collections-- for the foreign attributes on the ChildTbl and eager fetching will work as expected. If you must use Collections, I read somewhere that setting the hibernate annotation @Fetch(FetchMode.SUBSELECT) on bags (Collections) may work or you may use a List with an @IndexColumn.
For example:
Under ChildTbl.java
(Similarly, update ParentTbl.java and GrandchildTbl.java. They would have @OneToMany relationships with ParentChildTbl.java and ChildGrandchildTbl.java, respectively)
| ...
| @Id
| @GeneratedValue(generator = "system-uuid")
| @Column(name = "child_id", nullable = false)
| private String childId;
|
| @Column(name = "notes")
| private String notes;
|
| @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "childTbl")
| private Set<ParentChildTbl> parentChildTblSet
|
| @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "childTbl")
| private Set<ChildGrandchildTbl> grandchildTblSet;
| ...
|
Create ChildGrandchildTbl.java (Similarly create ParentChildTbl.java)
| ...
| @EmbeddedId
| protected ChildGrandchildPK childGrandchildPK;
|
| @JoinColumn(name = "child_id", insertable = false, nullable = false, updatable = false)
| @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
| private ChildTbl childTbl;
|
| @JoinColumn(name = "grandchild_id", insertable = false, nullable = false, updatable = false)
| @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
| private GrandchildTbl grandchildTbl;
| ...
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4205671#4205671
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4205671
16 years, 10 months
[Clustering/JBoss] - Re: Invocation of startSingleton()
by bstansberry@jboss.com
Hmm, simple question, complicated answer from me.
First, I'll cut to the bottom line. Instead of deploying via a -service.xml, use a -jboss-beans.xml:
| <?xml version="1.0" encoding="UTF-8"?>
|
| <deployment xmlns="urn:jboss:bean-deployer:2.0">
|
| <bean name="StartupTestingCFD2" class="com.xitee.cfd.be2.StartupService2">
|
| <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="test:service=StartupTestingCFD2", exposedInterface=org.jboss.ha.singleton.examples.HASingletonMBeanExampleMBean.class, registerDirectly=true)</annotation>
|
| </bean>
|
| <bean name="HASingletonController"
| class="org.jboss.ha.singleton.HASingletonController">
|
| <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="test:service=HASingletonController", exposedInterface=org.jboss.ha.singleton.HASingletonControllerMBean.class, registerDirectly=true)</annotation>
|
|
| <property name="HAPartition"><inject bean="HAPartition"/></property>
| <property name="target"><inject bean="StartupTestingCFD2"/></property>
| <property name="targetStartMethod">startSingleton</property>
| <property name="targetStopMethod">stopSingleton</property>
|
| </bean>
|
| </deployment>
|
Now, the details.
First, deploying via a -service.xml should work. But in actually deploying an example to test it before posting here I found a bug: https://jira.jboss.org/jira/browse/JBAS-6435 . Hopefully that will be fixed for 5.0.1 which is due out soon.
Now, let's assume JBAS-6435 were fixed and you could use a -service.xml. It would look like this:
| <server>
|
| <mbean code="com.xitee.cfd.be2.StartupService2"
| name="test:service=StartupTestingCFD2">
| </mbean>
|
| <mbean code="org.jboss.ha.singleton.HASingletonController"
| name="test:service=HASingletonController">
|
| <attribute name="HAPartition"><inject bean="HAPartition"/></attribute>
|
| <attribute name="TargetName">test:service=StartupTestingCFD22</attribute>
| <attribute name="TargetStartMethod">startSingleton</attribute>
| <attribute name="TargetStopMethod">stopSingleton</attribute>
| </mbean>
|
| </server>
There were two problems with your XML:
1) The values for the "name" attribute on your mbean elements were invalid. The value needs to be a legal JMX ObjectName.
2) I need to update the AS 5 docs need to be to specify how to dependency inject the HAPartition, i.e.
<attribute name="HAPartition"><inject bean="HAPartition"/></attribute>
instead of
<depends optional-attribute-name="ClusterPartition"
| proxy-type="attribute">jboss:service=${jboss.partition.name:DefaultPartition}</depends>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4205655#4205655
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4205655
16 years, 10 months