[EJB 3.0] - Re: Compound primary key with cmr
by Ajaleo
Thanks,
this is a excerpt of the code:
Class Person:
| @Entity
| public class Persona implements Serializable {
|
| @EmbeddedId
| private PersonaPK pK;
|
| @Transient
| private Pais pais;
|
| private String nombre;
|
| private String numTelefono;
|
| /** Creates a new instance of Persona */
| public Persona() {
| }
|
|
|
|
| public String getNombre() {
| return nombre;
| }
|
| public void setNombre(String nombre) {
| this.nombre = nombre;
| }
|
| public String getNumTelefono() {
| return numTelefono;
| }
|
| public void setNumTelefono(String numTelefono) {
| this.numTelefono = numTelefono;
| }
|
| public String toString() {
| return "" + this.getPK().getDni();
| }
|
|
| @JoinColumn(name="IDPAIS")
| @ManyToOne
| public Pais getPais() {
| return pais;
| }
|
| public void setPais(Pais pais) {
| this.pais = pais;
| }
|
| public PersonaPK getPK() {
| return pK;
| }
|
| public void setPK(PersonaPK pK) {
| this.pK = pK;
| }
|
| @Transient
| public Long getDni() {
| return pK.getDni();
| }
|
| public void setDni(Long dni) {
| pK.setDni(dni);
| }
|
| }
|
Class Country
| @Entity
| public class Pais implements Serializable {
|
| @Id
| @GeneratedValue(strategy = GenerationType.AUTO)
| private Long id;
|
|
| private String nombre;
|
| private String moneda;
|
| @OneToMany(mappedBy="pais")
| private List<Persona> habitantes;
|
| /** Creates a new instance of Pais */
| public Pais() {
| }
|
| public Long getId() {
| return id;
| }
|
| public void setId(Long id) {
| this.id = id;
| }
|
| public String toString() {
| //TODO change toString() implementation to return a better display name
| return "" + this.getId();
| }
|
| public String getNombre() {
| return nombre;
| }
|
| public void setNombre(String nombre) {
| this.nombre = nombre;
| }
|
| public String getMoneda() {
| return moneda;
| }
|
| public void setMoneda(String moneda) {
| this.moneda = moneda;
| }
|
| public List<Persona> getHabitantes() {
| return habitantes;
| }
|
| public void setHabitantes(List<Persona> habitantes) {
| this.habitantes = habitantes;
| }
|
| }
|
|
|
And the primary key
| @Embeddable
| public class PersonaPK implements Serializable {
|
|
| private Long dni;
|
|
| private Long idPais;
|
| /** Creates a new instance of PersonaPK */
| public PersonaPK() {
| }
|
| public PersonaPK(Long dni,Long idPais) {
| this.dni=dni;
| this.idPais=idPais;
| }
|
| public String toString() {
| return "" + this.getDni();
| }
|
|
| @Id
| public Long getDni() {
| return dni;
| }
|
| public void setDni(Long dni) {
| this.dni = dni;
| }
|
|
|
| public boolean equals(Object obj) {
| if (obj == this) return true;
| if (!(obj instanceof PersonaPK))
| return false;
| PersonaPK pk = (PersonaPK)obj;
|
| if (!getDni().equals(pk.getDni()))
| return false;
| if (!getIdPais().equals(pk.getIdPais()))
| return false;
| return true;
| }
| public int hashCode( ) {
| return getDni().hashCode( ) + getIdPais().hashCode();
| }
|
| @Id
| public Long getIdPais() {
| return idPais;
| }
|
| public void setIdPais(Long idPais) {
| this.idPais = idPais;
| }
|
|
| }
|
I've needed to use Transient so the container create SQL sentences without duplicate columns. However if the relation between (Pais-Persona) is bidirectional Jboss tell me
org.hibernate.AnnotationException: mappedBy reference an unknown property com.mycompany.theapp.Persona.pais
I think that's because I've used transient in the field pais of the entity Persona.
Briefly, the main problem is that I can't establish a bidirectional relation between two entities and the primary keys of one of the two entities is composed by a field which is a CMR too.
Please, if somebody need more explanations ask me.
Thanks a lot!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3962421#3962421
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3962421
18 years, 5 months
[JBossCache] - Eviction Policy problem cache clear
by Gorshkov
Hi,
I try tune JbossCache
Object stored in JBoss cache successfully. But I can't remove Object from cache use EvictionPolicy.
(JBoss 4.0.4.GA + JbossCache 1.4.0.GA + EJB 3.0 RC8)
ejb3-entity-cache-service.xml:
| ...
| <mbean code="org.jboss.cache.TreeCache" name="jboss.cache:service=TreeCache">
| ...
| <attribute name="CacheMode">LOCAL</attribute>
| ...
| <!-- Name of the eviction policy class. -->
| <attribute name="EvictionPolicyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
|
| <!-- Specific eviction policy configurations. This is LRU -->
| <attribute name="EvictionPolicyConfig">
| <config>
| <attribute name="wakeUpIntervalSeconds">5</attribute>
| <!-- Cache wide default -->
| <region name="/_default_">
| <attribute name="maxNodes">5</attribute>
| <attribute name="timeToLiveSeconds">10</attribute>
| <attribute name="maxAgeSeconds">15</attribute>
| </region>
| </config>
| </attribute>
| ...
|
persistence.properties :
hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManager# Clustered cache with TreeCache
| hibernate.cache.provider_class=org.jboss.ejb3.entity.TreeCacheProviderHook
| hibernate.treecache.mbean.object_name=jboss.cache:service=TreeCache
| hibernate.dialect=org.hibernate.dialect.SQLServerDialect
| hibernate.jndi.java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
| hibernate.jndi.java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
| hibernate.bytecode.use_reflection_optimizer=false
| # I don't think this is honored, but EJB3Deployer uses it
| hibernate.bytecode.provider=javassist
|
console log:
2006-08-02 14:17:15,807 DEBUG [org.jboss.cache.eviction.LRUConfiguration] parseConfig: name -- /_default_ maxNodes -- 5
| timeToLiveSeconds -- 10 maxAgeSeconds -- 15
|
I'm start project. JBoss cache successfully, but NumberOfNodes more then 5 and after 10 second cache not clear. Why? Where I'm wrong?
Thanks in advance.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3962420#3962420
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3962420
18 years, 5 months
[JNDI/Naming/Network] - Re: RMI-IIOP
by One_Special_User
It's me ... again :-)
Ok, i tried a different approach.
I've got a SessionBean A and a SessionBean B.
Have to use IIOP as stated above.
My ejb-jar.xml looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
| <ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
| <display-name>MyStuff-ejb</display-name>
|
| <enterprise-beans>
| <session>
| <display-name>B</display-name>
| <ejb-name>B</ejb-name>
| <home>mypkg.BHome</home>
| <remote>mypkg.B</remote>
| <ejb-class>mypkg.BBean</ejb-class>
| <session-type>Stateful</session-type>
| <transaction-type>Container</transaction-type>
| </session>
| <session>
| <display-name>A</display-name>
| <ejb-name>A</ejb-name>
| <home>mypkg.AHome</home>
| <remote>mypkg.A</remote>
| <ejb-class>mypkg.ABean</ejb-class>
| <session-type>Stateless</session-type>
| <transaction-type>Container</transaction-type>
| <ejb-ref>
| <ejb-ref-name>ejb/A</ejb-ref-name>
| <ejb-ref-type>Session</ejb-ref-type>
| <home>mypkg.AHome</home>
| <remote>mypkg.A</remote>
| <ejb-link>A</ejb-link>
| </ejb-ref>
| </session>
| </enterprise-beans>
|
| <assembly-descriptor>
| <container-transaction>
| <method>
| <ejb-name>B</ejb-name>
| <method-name>*</method-name>
| </method>
| <trans-attribute>Required</trans-attribute>
| </container-transaction>
| <container-transaction>
| <method>
| <ejb-name>A</ejb-name>
| <method-name>*</method-name>
| </method>
| <trans-attribute>Required</trans-attribute>
| </container-transaction>
| </assembly-descriptor>
| </ejb-jar>
|
My jboss.xml looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
| <jboss>
| <enterprise-beans>
|
| <session>
| <ejb-name>A</ejb-name>
| <jndi-name>mystuff/A</jndi-name>
| <invoker-bindings>
| <invoker>
| <invoker-proxy-binding-name>iiop</invoker-proxy-binding-name>
| </invoker>
| </invoker-bindings>
| </session>
|
| <session>
| <ejb-name>B</ejb-name>
| <jndi-name>mystuff/B</jndi-name>
| <invoker-bindings>
| <invoker>
| <invoker-proxy-binding-name>iiop</invoker-proxy-binding-name>
| </invoker>
| </invoker-bindings>
| </session>
|
| </enterprise-beans>
| </jboss>
A makes use of B, so i have to look it up in order to invoke.
In ABean, I've tried to look up B via
Context ctx = new InitialContext()
followed by either
"ctx.lookup("java:comp/env/ejb/VFMSession")" or "ctx.lookup( "mystuff/B" )", but none works.
How to get a reference to BHome??!
Should I change my jndi.properties?
| java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
| java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
|
| #java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3962413#3962413
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3962413
18 years, 5 months