openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pietia <pietia....@gmail.com>
Subject Re: Question about @OneToMany
Date Sun, 11 May 2008 17:22:56 GMT

hi there !

Is possible to define @OneToMany realtionship
without using join table ? (i saw that in book about Ejb 3.0).

i use openjpa and when i'm trying to do simple
realtionship A-B, as follows :

@Entity
public class Address implements Serializable {

	private Integer	id;
	private String	street;
	private String	city;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Integer getId() {
		return id;
	}

...
}


@Entity
public class Customer implements Serializable {

	private Integer				id;
	private String				name;
	private String				surname;
	private Collection<Address>	address = new ArrayList<Address>();

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}

	@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
	@JoinColumn(name = "Address_id")   
	public Collection<Address> getAddress() {
		return address;
	}

...
}

Client:

public class Testuj {
	public static void main(String[] args) {
		Properties prop = new Properties();
		prop.put(
					Context.INITIAL_CONTEXT_FACTORY,
					"org.apache.openejb.client.RemoteInitialContextFactory");
		prop.put("java.naming.provider.url", "ejbd://localhost:4201");
		try {
			Context context = new InitialContext(prop);
			try {
				CustomerManagerRemote cmr = (CustomerManagerRemote) context
						.lookup("CustomerManagerRemote");

				Customer customer = new Customer();
				customer.setName("Anna");
				customer.setSurname("Maria");

				ArrayList<Address> addresses = (ArrayList<Address>)
customer.getAddress();
				
				Address address = new Address();
				address.setCity("New York");
				address.setStreet("Nieprawdopodna 12/123");
				
				addresses.add(address);
				customer.setAddress(addresses);
				cmr.addCustomer(customer);

			} catch (Exception e) {
				e.printStackTrace();
			}
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}
}

.. i gets:

javax.ejb.EJBException: The bean encountered a non-application exception.;
nested exception is: 
	<openjpa-1.0.2-r420667:627158 fatal user error>
org.apache.openjpa.persistence.ArgumentException: You have supplied columns
for "org.testowa.Customer.address", but this mapping cannot have columns in
this context.
	at
org.apache.openejb.client.EJBInvocationHandler.convertException(EJBInvocationHandler.java:219)
	at
org.apache.openejb.client.EJBObjectHandler._invoke(EJBObjectHandler.java:157)
	at
org.apache.openejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:117)
	at
org.apache.openejb.client.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:52)
	at $Proxy0.addCustomer(Unknown Source)
	at org.testowa.Testuj.main(Testuj.java:44)
Caused by: <openjpa-1.0.2-r420667:627158 fatal user error>
org.apache.openjpa.persistence.ArgumentException: You have supplied columns
for "org.testowa.Customer.address", but this mapping cannot have columns in
this context.
	at
org.apache.openjpa.jdbc.meta.MappingInfo.assertNoSchemaComponents(MappingInfo.java:327)
	at
org.apache.openjpa.jdbc.meta.strats.RelationToManyTableFieldStrategy.map(RelationToManyTableFieldStrategy.java:96)
	at
org.apache.openjpa.jdbc.meta.strats.RelationCollectionTableFieldStrategy.map(RelationCollectionTableFieldStrategy.java:94)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:120)
	at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:80)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.java:438)
	at org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:403)
	at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.java:812)
	at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1618)
	at
org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:675)
	at
org.apache.openjpa.meta.MetaDataRepository.resolveMapping(MetaDataRepository.java:636)
	at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:514)
	at
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:302)
	at
org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:282)
	at
org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java:673)
	at
org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(MappingTool.java:745)
	at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:643)
	at
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:164)
	at
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:130)
	at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:188)
	at
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
	at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
	at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
	at
org.apache.geronimo.persistence.CMPEntityManagerTxScoped.createEntityManager(CMPEntityManagerTxScoped.java:74)
	at
org.apache.geronimo.persistence.CMPEntityManagerTxScoped.getEntityManager(CMPEntityManagerTxScoped.java:55)
	at
org.apache.geronimo.persistence.CMPEntityManagerTxScoped.persist(CMPEntityManagerTxScoped.java:81)
	at org.testowa.CustomerManagerBean.addCustomer(CustomerManagerBean.java:15)
	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:597)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:158)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:141)
	at
org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:67)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:210)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:188)
	at
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
	at
org.apache.openejb.server.ejbd.EjbRequestHandler.doEjbObject_BUSINESS_METHOD(EjbRequestHandler.java:238)
	at
org.apache.openejb.server.ejbd.EjbRequestHandler.processRequest(EjbRequestHandler.java:129)
	at
org.apache.openejb.server.ejbd.EjbDaemon.processEjbRequest(EjbDaemon.java:164)
	at org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:122)
	at org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:84)
	at org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:60)
	at org.apache.openejb.server.ServicePool$2.run(ServicePool.java:78)
	at org.apache.openejb.server.ServicePool$3.run(ServicePool.java:101)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
	at java.lang.Thread.run(Thread.java:619)

what may be wronq ? 

pietia

-- 
View this message in context: http://www.nabble.com/Question-about-%40OneToMany-tp16840368p17170612.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message