-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: many to many problem. Please help
PostPosted: Mon Jul 04, 2005 10:01 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 5:07 am
Posts: 33
I am having 2 classes and I created a many to many table. However I get an exception when trying to add data to this table. Here is my code. what am I doing wrong?

class Device:

private Set supportedFeatures = new HashSet();

/**
* @hibernate.set
* table="DEVICE_DEVICEFEATURE"
* cascade="all"
* inverse="false"
*
* @hibernate.collection-key
* column="DEVICE_ID"
*
* @hibernate.collection-many-to-many
* class="Feature"
* column="FEATURE_ID"
*
* @return the supportedFeatures.
*/
public Set getSupportedFeatures() {
return supportedFeatures;
}

//--------------------------------------------------
/**
* @param supportedFeatures The supportedFeatures to set.
*/
public void setSupportedFeatures(Set supportedFeatures) {
this.supportedFeatures = supportedFeatures;
}


Class Feature:

private Set associatedDevices = new HashSet();

/**
* @hibernate.set
* table="DEVICE_DEVICEFEATURE"
* cascade="all"
*
* @hibernate.collection-key
* column="FEATURE_ID"
*
* @hibernate.collection-many-to-many
* class="Device"
* column="DEVICE_ID"
*
* @return Returns the associatedDevices.
*/
public Set getAssociatedDevices() {
return associatedDevices;
}
/**
* @param associatedDevices The associatedDevices to set.
*/
public void setAssociatedDevices(Set associatedDevices) {
this.associatedDevices = associatedDevices;
}



The code for inserting new Device and new Feature to their table and to the many to many table:
Device objDevice;
objDevice = DeviceTest.createDevice();
insertObject(objDevice);


Feature objFeature;
objFeature = FeatureTest.createFeature();
insertObject(objFeature);

Set mySet = objFeature.getAssociatedDevices();
mySet.add(objDevice);
objFeature.setAssociatedDevices(mySet);


Set mySet1 = objDevice.getSupportedFeatures();
mySet1.add(objFeature);
objDevice.setSupportedFeatures(mySet1);

updateObject(objDevice);
updateObject(objFeature);

Running this code I get an Exception:
net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of Device.supportedFeatures
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:68)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:222)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:924)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:857)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:779)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at test.com.synchronica.cp.repository.RepositoryTest.insertObject(RepositoryTest.java:211)
at test.com.synchronica.cp.repository.FullTest.testInsert(FullTest.java:56)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
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:324)
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:38)
... 22 more


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.