Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Id classes fail to populate in JpaMetamodelEntityInformation [DATAJPA-413] #821

Closed
spring-projects-issues opened this issue Oct 10, 2013 · 30 comments
Assignees
Labels
in: core type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Oct 10, 2013

Brian Chase opened DATAJPA-413 and commented

I have 2 JPA entities that have compound keys, and so both are using the @IdClass object to store the compound primary key.

The first entity and id class uses two integers as the compound key.

 
@Entity
@IdClass(ItemId.class)
public class Item {
	
	@Id
	@Column(columnDefinition = "INT")
	private Integer id;

	@Id
	@Column(name = "sales_device_id", columnDefinition = "INT")
	private Integer salesDeviceId;

	....
}


public class ItemId implements Serializable {
	
	public Integer id;
	
	public Integer salesDeviceId;

	....
}

The second entity and id class uses three integers as the compound key, however I am using entities as the @Id values. Two of the primary key columns are part of the Item entity, and the third column belongs to the Site entity.

 
@Entity
@IdClass(ItemSiteId.class)
public class ItemSite {
	
	@Id
	@ManyToOne
	private Item item;
	
	@Id
	@ManyToOne
	private Site site;

	....
}

For this case the Id class for ItemSite must use the Id class from Item as described in the OpenJPA documentation in example 5.6 http://openjpa.apache.org/builds/2.2.2/apache-openjpa/docs/ref_guide_pc_oid.htmll

 
public class ItemSiteId implements Serializable {
	
	public ItemId item;
	
	public Integer site;

	....
}

Using these nested Id classes, spring data throws an exception of type conversion failure from the JpaMetamodelEntityInformation class. After downloading version 1.4.1 source, I applied a rewrite of the IdentifierDerivingDirectFieldAccessFallbackBeanWrapper method setPropertyValue (around line 323 in JpaMetamodelEntityInformation) and it resolves the exception.

Here is my change:

 
@Override
public void setPropertyValue(String propertyName, Object value) {

	if (isIdentifierDerivationNecessary(value)) {

		// Derive the identifer from the nested entity that is part of the composite key.
		@SuppressWarnings({ "rawtypes", "unchecked" })
		JpaMetamodelEntityInformation nestedEntityInformation = new JpaMetamodelEntityInformation(value.getClass(),
				this.metamodel);
		
		super.setPropertyValue(propertyName, nestedEntityInformation.getId(value));
		return;
	}

	super.setPropertyValue(propertyName, value);
}

Affects: 1.4.1

Reference URL: http://openjpa.apache.org/builds/2.2.2/apache-openjpa/docs/ref_guide_pc_oid.html

Attachments:

Referenced from: pull request #133

Backported to: 1.10.3 (Hopper SR3), 1.9.5 (Gosling SR5)

8 votes, 11 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 3, 2014

Oliver Drotbohm commented

What exception are you seeing exactly? Care to provide a tiny example project to reproduce the issue?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 21, 2014

Brian Chase commented

use the ddl.sql to create the tables, set your DB credentials in the pom.xml and run the ItemRepositoryTest unit test to see the crash.

org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.Integer' to required type 'com.datajpa.ItemId' for property 'item'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.Integer] to required type [com.datajpa.ItemId] for property 'item': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:485)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:516)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1119)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:904)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation$DirectFieldAccessFallbackBeanWrapper.setPropertyValue(JpaMetamodelEntityInformation.java:290)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation$IdentifierDerivingDirectFieldAccessFallbackBeanWrapper.setPropertyValue(JpaMetamodelEntityInformation.java:333)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.getId(JpaMetamodelEntityInformation.java:123)
at org.springframework.data.repository.core.support.AbstractEntityInformation.isNew(AbstractEntityInformation.java:51)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.isNew(JpaMetamodelEntityInformation.java:190)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:357)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 21, 2014

Brian Chase commented

See the attached file for a nested Id class project producing the exception

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 18, 2014

Oliver Drotbohm commented

Thomas Darimont, you've implemented the latest improvements in that area. Quick to judge, whether this one might still occur?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 18, 2014

Thomas Darimont commented

I give it a spin

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 18, 2014

Thomas Darimont commented

Seems that this is still an issue, just tried this with SD JPA 1.6.1 and Spring Framework 3.2.9, as well as with the latest SD JPA Snapshot and Spring Framework 4.0.5.

I also get the exception mentioned above:

org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.Integer' to required type 'com.datajpa.ItemId' for property 'item'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.Integer] to required type [com.datajpa.ItemId] for property 'item': no matching editors or conversion strategy found
	at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:474)
	at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:511)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1119)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902)
	at org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper.setPropertyValue(DirectFieldAccessFallbackBeanWrapper.java:73)
	at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation$IdentifierDerivingDirectFieldAccessFallbackBeanWrapper.setPropertyValue(JpaMetamodelEntityInformation.java:306)
	at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.getId(JpaMetamodelEntityInformation.java:134)
	at org.springframework.data.repository.core.support.AbstractEntityInformation.isNew(AbstractEntityInformation.java:51)
	at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.isNew(JpaMetamodelEntityInformation.java:197)
	at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:388)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:443)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:428)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:382)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
	at com.sun.proxy.$Proxy32.save(Unknown Source)
	at com.datajpa.repositories.ItemRepositoryTest.testSetGetDelete(ItemRepositoryTest.java:94)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.Integer] to required type [com.datajpa.ItemId] for property 'item': no matching editors or conversion strategy found
	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267)
	at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:459)
	... 59 more

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 18, 2014

Oliver Drotbohm commented

I've just looked up the JPA spec, and it seems the approach that is taken is invalid. The bullet list in section 2.4 explicitly states:

  • If the composite primary key class is represented as an id class, the names of primary key fields or properties in the primary key class and those of the entity class to which the id class is mapped must correspond and their types must be the same.

So JPA is clearly expecting type matches of the properties in entity and id class

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 9, 2015

Jeff Osborn commented

Oliver, I don't think that 2.4 is the problem he, and myself, are hitting. This error:

org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.Integer' to required type 'com.datajpa.ItemId' for property 'item'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.Integer] to required type [com.datajpa.ItemId] for property 'item': no matching editors or conversion strategy found

Is due to the fact that hibernate's JpaMetamodelEntityInformation.setPropertyValue() method we hit the if (isIdentifierDerivationNecessary(value)) { and that returns true for a value of type com.datajpa.ItemId,
then the identifier (ItemId) gets stripped down to it's primative form nestedIdPropertyValue (which is an Integer).
Then when we try to setPropertyValue with the Integer it does not match the ItemId. and we get the error shown above.

It is like we need to go with (psudo code):

if (isIdentifierDerivationNecessary(value) AND getClassForProperty(propertyName) instanceof value) {

From... JpaMetamodelEntityInformation....:

@Override
public void setPropertyValue(String propertyName, Object value) {
     if (isIdentifierDerivationNecessary(value)) {
          // Derive the identifer from the nested entity that is part of the composite key.
          @SuppressWarnings({ "rawtypes", "unchecked" })
          JpaMetamodelEntityInformation nestedEntityInformation = new JpaMetamodelEntityInformation(value.getClass(),
                            this.metamodel);
          Object nestedIdPropertyValue = new DirectFieldAccessFallbackBeanWrapper(value)
                            .getPropertyValue(nestedEntityInformation.getIdAttribute().getName());
          super.setPropertyValue(propertyName, nestedIdPropertyValue);
          return;
     }
     super.setPropertyValue(propertyName, value);
}

Please fix as I have not seen any work arounds, since @EmbeddedId was taken away.
Thanks,
Jeff

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 10, 2015

Oliver Drotbohm commented

Would you mind clarifying what you mean by "since @EmbeddedId was taken away"?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 10, 2015

Thomas Darimont commented

Hello Jeff,

I gave this another spin - we now try to extract the id attributes from IdClass typed properties more eagerly.
Would you mind giving the attached PR a try? #133

With the PR in place I could successfully run the tests from the attached sample project (after upgrading to SD-JPA 1.8.0-BUILD-SNAPSHOT).
The sample project can be found here: https://github.com/thomasdarimont/spring-data-jpa-DATAJPA-413

Cheers,
Thomas

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 10, 2015

Jeff Osborn commented

Oliver, I believe that Hibernate core 4.x broke the @EmbeddedId, and they suggest that you use the @IdClass(ItemId.class) class annotation.

Thomas, thanks for the edit, and I just pulled those changes and will let you know how it works :)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 19, 2015

Angel D. Segarra commented

I just hit this bug. Is there a workaround?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 20, 2015

Angel D. Segarra commented

Thomas, I can confirm this fixed it for me. Thanks!

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 20, 2015

Jeff Osborn commented

Thomas,

Unfortunately I have been having problems building from that branch (company certs Grrr), and then I got pulled off on other things. It is on my to do list to test this, however it looks like we already have two successful test cases that are working with this fix. So that is great.
I will update you when I get a chance to run my test case.
Sorry for the delay...
Jeff

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 26, 2015

Jeff Osborn commented

Thomas,

I was able to get your changes, and it did not fix my test case :(.

However, I have simplified the fix, but due to my company certs issue I was unable to run your unit tests, and/or directly check out from your branch.

If I provide you with the canges, can you apply them and run your tests?

@Angel D. Segarra should run her tests as well.

I have made changes to 3 methods as follows (from the Main Branch, not your branch).....

	public ID getId(T entity) {

		BeanWrapper entityWrapper = new DirectFieldAccessFallbackBeanWrapper(entity);

		if (idMetadata.hasSimpleId()) {
			return (ID) entityWrapper.getPropertyValue(idMetadata.getSimpleIdAttribute().getName());
		}

		IdentifierDerivingDirectFieldAccessFallbackBeanWrapper idWrapper = new IdentifierDerivingDirectFieldAccessFallbackBeanWrapper(idMetadata.getType(), metamodel);
		boolean partialIdValueFound = false;

		for (SingularAttribute<? super T, ?> attribute : idMetadata) {
			Object propertyValue = entityWrapper.getPropertyValue(attribute.getName());

			if (propertyValue != null) {
				partialIdValueFound = true;
			}

			idWrapper.setPropertyValue(attribute, propertyValue);
		}

		return (ID) (partialIdValueFound ? idWrapper.getWrappedInstance() : null);
	}
.........................
		public void setPropertyValue(SingularAttribute<?, ?> attribute , Object value) {

			if (!isIdentifierDerivationNecessary(attribute, value)) {
				super.setPropertyValue(attribute.getName(), value);
				return;
			}

			// Derive the identifer from the nested entity that is part of the composite key.		
			@SuppressWarnings({ "rawtypes", "unchecked" })		
			JpaMetamodelEntityInformation nestedEntityInformation = new JpaMetamodelEntityInformation(value.getClass(),		
					this.metamodel);		
			Object nestedIdPropertyValue = new DirectFieldAccessFallbackBeanWrapper(value)
					.getPropertyValue(nestedEntityInformation.getIdAttribute().getName());
			super.setPropertyValue(attribute.getName(), nestedIdPropertyValue);

			return;
		}

		/**
		 * @param value
		 * @return {@literal true} if the given value is not {@literal null} and a mapped persistable entity otherwise
		 *         {@literal false}
		 */
		private boolean isIdentifierDerivationNecessary(SingularAttribute<?, ?> attribute , Object value) {
			if (value == null) {
				return false;
			}
			// if the value is the same as the instance of the composite ID's attribute
			// then we don't need further identifier derivation
			if (attribute.getJavaType().isInstance(value)) {
				return false;
			}

			try {
				ManagedType<? extends Object> managedType = this.metamodel.managedType(value.getClass());
				return managedType != null && managedType.getPersistenceType() == PersistenceType.ENTITY;
			} catch (IllegalArgumentException iae) {
				// no mapped type
				return false;
			}
		}

Sorry I could not just check it in directly.

Also notice that this change did work with the additional code you put in there (like tryFindSingularIdAttributeNameOrUseFallback()), however it did not help my case so I pulled it for simplicity (it may help for Angel?????)

Please let me know in which release this will be included.

Thanks,

Jeff

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 24, 2015

Angel D. Segarra commented

Hi,

There hasn't been an update for this bug in a while and I noticed 1.8 was released recently. I am currently using a build specific for this bug as a temporary solution. I wonder why this bug is classified as minor? it seems like a fairly common and simple use case. in our case it was a show stopper

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 27, 2015

Angel D. Segarra commented

Is there anything I can do to help accelerate this bugfix being accepted?

This bug breaks a valid JPA spec I wonder why is it considered a minor pirority bug? Is it because it's considered a rare use case? It's been open for going on 2 and a half years... What am I missing?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 28, 2015

Jeff Osborn commented

Angle,

Did you try the fix that I have above?

As I said, my firewall here does not let me download everything needed to do a real build and run the tests to verify that it does not break anything else....

I would be interested to see if it fixes your problem(s).

Thanks,

Jeff

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 22, 2015

Thomas Darimont commented

Hi Angel, Hi Jeff,

since this PR works for the other guys - may I ask you for some test model that resembles what you are doing?
Jeff I tried to integrate your proposal into the PR but it doesn't work with the sample model from this issue (see above).

Since we want to have a solution that works for all we need those models as well for testing.

Cheers,
Thomas

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 22, 2015

Angel D. Segarra commented

Hi Thomas:

My use case is basically identical to the one reported and the PR fix is what we are using for now, I have not had time to try Jeff's proposed fix but if it did not work on the sample model you have it probably wont work on mine. Let me know if you still require a test model from me and I'll try to get that done today.

-Angel

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 22, 2015

Jeff Osborn commented

Hi All,

My case, to put it in your example is that. Model differences are as follows:

  1. ItemSite object has an extra string field relationshipType
  2. Item has a set of ItemSite objects
@OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL, mappedBy="item")
private Set<ItemSite> itemSites = new HashSet<ItemSite>(0); 
  1. the ItemSiteId class has the same Object references as to Item and Site as shown in ItemSite

The exception happens when I use ItemSiteId in a repository as follows:
public interfaceItemSiteRepository extends CrudRepository<ItemSite, ItemSiteId>{
}

And then I try to load ItemSite objects using a populated ItemSiteId object as follows:

 

 @Test
    public void testItemSiteToString() {        
        
        SiteUsageType SiteUsageType = SiteUsageTypeRepository.findOne("SRVC");
        assertNotNull(SiteUsageType);        
        
        Item Item = ItemRepository.findOne(360L);
        assertNotNull(Item);
        
        Site Site = SiteRepository.findOne(4032L);
        assertNotNull(Site);
        
        // create ItemSiteId object by using constructor
        ItemSiteId ItemSiteId = new ItemSiteId(Item,Site,SiteUsageType);  
        assertNotNull(ItemSiteId);
        
        // THIS IS WHERE IT BARFS
        ItemSite ItemSite = ItemSiteRepository.findOne(ItemSiteId);
        assertNotNull(ItemSite);
    
        assertNotNull(ItemSite.toString());
    }

I hope that helps,

Jeff

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 5, 2015

Angel D. Segarra commented

Jeff:
Can you provide the exception you get? I have a use case similar to yours with an extra attribute component to the Id class and I get no exception with the proposed fix.

Thomas:

I see the bug is "Waiting for feedback from reporter", considering this bug was first reported 10/Oct/13 and the reporter has not responded in a while, is there any way I can help to accelerate this bug? I could spare some time this weekend to give you what you need

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 10, 2015

Oliver Drotbohm commented

Any kind of feedback is appreciated. You might wanna try the feature branch build with version 1.9.0.DATAJPA-413-SNAPSHOT

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 10, 2015

Angel D. Segarra commented

Oliver:

I couldn't find a build for that feature branch in the spring snapshot repo but I tried with 1.8.0.DATAJPA-413-SNAPSHOT and It's working for me

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 9, 2015

Oliver Drotbohm commented

Thomas Darimont - I am inclined to merge the changes. Do you think we could add a dedicated test case?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 16, 2015

Jeff Osborn commented

Oliver,
Can you use what I added above to re-create this issue, then try the fix?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 23, 2015

jonas.lima commented

i've the same issue.

@Entity(name = "PosicaoPerformance")
@Table(name = "PERFORMANCE_POSICAO", schema = "dbo")
@IdClass(PosicaoPk.class)
public class Posicao implements Serializable {
....
@Id
	@MapsId("elemento")
	@ManyToOne(fetch = FetchType.LAZY)
	@LazyCollection(LazyCollectionOption.EXTRA)
	@JoinColumn(name = "idElemento", referencedColumnName = "id", updatable = false, insertable = false)
	private Elemento elemento;
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.Integer' to required type 'br.com.bbdtvm.grc.performance.modelo.Elemento' for property 'elemento'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.Integer] to required type [br.com.bbdtvm.grc.performance.modelo.Elemento] for property 'elemento': no matching editors or conversion strategy found
	at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:591)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 23, 2015

Jeff Osborn commented

Hi Jonas,
Please look back up these comments. I have some code that can be inserted into one of their hibernate classes. Then just put that into your codebase under the right folders like org.hibernate... and it should fix your problem. It looks as if they are looking into this problem now, but until they have a beta build for you. We have several projects running this way. Not optimal, but it works.

Let us know if that works for you.

Good luck,
Jeff

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 23, 2015

jonas.lima commented

Maybe change to hibernate 5 could resolve this issue?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 18, 2016

Mark Paluch commented

Added tests and a guard against null values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: bug
Projects
None yet
Development

No branches or pull requests

2 participants