openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C N Davies" <...@cndavies.com>
Subject RE: Exception when doing join
Date Sun, 12 Jul 2009 03:59:28 GMT
Hi Mike,

 

This is my Address entity and my user entity:

 

 

/**

 * 

 */

package com.trm.core;

 

import java.io.Serializable;

 

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;

 

/**

 * @author chris

 *

 */

@Entity

public class Address implements Serializable {

 

                /**

                 * 

                 */

                private static final long serialVersionUID = 1L;

                private int id;

                private int type;

                private String building;

                private String apt;

                private String streetno;

                private String street;

                private String suburb;

                private String postcode;

                private String country;

                

                /**

                 * @return the id

                 */

                @Id @GeneratedValue

                public int getId() {

                                return id;

                }

 

                /**

                 * @return the type

                 */

                public int getType() {

                                return type;

                }

 

                /**

                 * @param type the type to set

                 */

                public void setType(int type) {

                                this.type = type;

                }

 

                /**

                 * @return the building

                 */

                public String getBuilding() {

                                return building;

                }

 

                /**

                 * @param building the building to set

                 */

                public void setBuilding(String building) {

                                this.building = building;

                }

 

                /**

                 * @return the apt

                 */

                public String getApt() {

                                return apt;

                }

 

                /**

                 * @param apt the apt to set

                 */

                public void setApt(String apt) {

                                this.apt = apt;

                }

 

                /**

                 * @return the streetno

                 */

                public String getStreetno() {

                                return streetno;

                }

 

                /**

                 * @param streetno the streetno to set

                 */

                public void setStreetno(String streetno) {

                                this.streetno = streetno;

                }

 

                /**

                 * @return the street

                 */

                public String getStreet() {

                                return street;

                }

 

                /**

                 * @param street the street to set

                 */

                public void setStreet(String street) {

                                this.street = street;

                }

 

                /**

                 * @return the suburb

                 */

                public String getSuburb() {

                                return suburb;

                }

 

                /**

                 * @param suburb the suburb to set

                 */

                public void setSuburb(String suburb) {

                                this.suburb = suburb;

                }

 

                /**

                 * @return the postcode

                 */

                public String getPostcode() {

                                return postcode;

                }

 

                /**

                 * @param postcode the postcode to set

                 */

                public void setPostcode(String postcode) {

                                this.postcode = postcode;

                }

 

                /**

                 * @return the country

                 */

                public String getCountry() {

                                return country;

                }

 

                /**

                 * @param country the country to set

                 */

                public void setCountry(String country) {

                                this.country = country;

                }

 

                /**

                 * @param id the id to set

                 */

                public void setId(int id) {

                                this.id = id;

                }

}

 

/**

 * 

 */

package com.trm.core;

 

import java.util.Collection;

 

import javax.persistence.CascadeType;

import javax.persistence.Entity;

import javax.persistence.JoinColumn;

import javax.persistence.OneToMany;

 

/**

 * @author chris

 *

 */

@Entity

public class User extends CoreObject {

 

                /**

                 * 

                 */

                private static final long serialVersionUID = 1L;

                private Collection <Address> addresses;

                

                /* (non-Javadoc)

                 * @see com.trm.core.CoreObject#getFieldNames()

                 */

 

                public User(){

                                

                }

 

                @Override

                protected String[] getFieldNames() {

                                // TODO Auto-generated method stub

                                return null;

                }

 

                /**

                 * @param addresses the addresses to set

                 */

                public void setAddresses(Collection <Address> addresses) {

                                this.addresses = addresses;

                }

 

                /**

                 * @return the addresses

                 */

                @OneToMany(cascade={CascadeType.ALL})

                //@JoinColumn(name="id")

                

                public Collection <Address> getAddresses() {

                                return addresses;

                }

 

                

}

 

 

From: Michael Dick [mailto:michael.d.dick@gmail.com] 
Sent: Sunday, 12 July 2009 8:24 AM
To: users@openjpa.apache.org; cnd@cndavies.com
Subject: Re: Exception when doing join

 

Hi,

I haven't been able to reproduce the problem you describe, could you post
the entire entity (or a subset that illustrates the problem)? 

BTW the JoinColumn is on the wrong side of the relationship in your example
you should see a different exception once you get past the access type
problem. Ie :
 <openjpa-1.2.0-r422266:683325 fatal user error>
org.apache.openjpa.persistence.ArgumentException: You have supplied columns
for "openjpa.users.cndavies.entities.UserEntity.addresses", but this mapping
cannot have columns in this context.
    at
org.apache.openjpa.jdbc.meta.MappingInfo.assertNoSchemaComponents(MappingInf
o.java:327)
    at
org.apache.openjpa.jdbc.meta.strats.RelationToManyTableFieldStrategy.map(Rel
ationToManyTableFieldStrategy.java:96)
    <snip>

-mike

On Sat, Jul 11, 2009 at 9:15 AM, C N Davies <cnd@cndavies.com> wrote:

I've not done this before so maybe I'm missing something basic but I have
followed the docs as far as I can see.



I have an Entity User, which I want to have multiple addresses so I simply
added a I thought were the appropriate annotations and members like so:



     private Collection <Address> addresses;



      */

     public void setAddresses(Collection <Address> addresses) {

           this.addresses = addresses;

     }



     @OneToMany(cascade={CascadeType.ALL})

     @JoinColumn(name="id")

     public Collection <Address> getAddresses() {

           return addresses;

     }



As soon as I add the @OneToMany annotation and OpenJPA starts to generate
the tables, it throws an exception complaining I am using both field and
property access, however the exception lists no members using field access
and only 1 using property access so I a not sure why it is telling me I am
using both.



Here is the stack trace, thanks for any advice!:



<openjpa-1.2.0-r422266:683325 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: Type "com.trm.core.User"
attempts to use both field and property access. Only one access method is
permitted. Field access is used on the following fields: []. Property access
is used on the following methods: [public java.util.Collection
com.trm.core.User.getAddresses()].


org.apache.openjpa.meta.AbstractMetaDataDefaults.populate(AbstractMetaDataDe
faults.java:161)


org.apache.openjpa.persistence.PersistenceMetaDataDefaults.populate(Persiste
nceMetaDataDefaults.java:227)


org.apache.openjpa.meta.MetaDataRepository.addMetaData(MetaDataRepository.ja
va:794)


org.apache.openjpa.meta.MetaDataRepository.addMetaData(MetaDataRepository.ja
va:780)


org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.getMetaDa
ta(AnnotationPersistenceMetaDataParser.java:657)


org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.parseClas
sAnnotations(AnnotationPersistenceMetaDataParser.java:480)


org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.parse(Ann
otationPersistenceMetaDataParser.java:352)


org.apache.openjpa.persistence.PersistenceMetaDataFactory.load(PersistenceMe
taDataFactory.java:229)


org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepos
itory.java:474)


org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.ja
va:294)


org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(MappingRepository.
java:285)


org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java:676)


org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(MappingTool.java:748)

       org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:646)


org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBro
kerFactory.java:153)


org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFac
tory.java:119)


org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFact
ory.java:189)


org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBroker
Factory.java:142)


org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
EntityManagerFactoryImpl.java:192)


org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
EntityManagerFactoryImpl.java:145)


org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
EntityManagerFactoryImpl.java:56)


com.trm.jpa.services.EntityService.createEntityManager(EntityService.java:73
)

       com.trm.jpa.services.EntityService.<init>(EntityService.java:34)


com.trm.beans.backing.CountryListBackingBean.init(CountryListBackingBean.jav
a:28)


com.trm.beans.backing.CountryListBackingBean.<init>(CountryListBackingBean.j
ava:33)

       sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)

       sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)

       sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)

       java.lang.reflect.Constructor.newInstance(Unknown Source)

       java.lang.Class.newInstance0(Unknown Source)

       java.lang.Class.newInstance(Unknown Source)


com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryIm
pl.java:275)


com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBea
ns(ApplicationAssociate.java:551)


com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:8
2)

       javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)


com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.
java:64)

       org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45)

       org.apache.el.parser.AstValue.getValue(AstValue.java:86)


org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)


org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:101
)

       javax.faces.component.UIData.getValue(UIData.java:582)


org.ajax4jsf.component.UIDataAdaptor.getValue(UIDataAdaptor.java:1624)




 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message