Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Error creating bean with name 'mySessionFactory' defined in class path:Error setting property values

 
Ranch Hand
Posts: 32
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have got problems instantiating a bean. here is the stack trace:


and the Course class:


and here is the beans.xml


Thanks priorly,
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Property "mappingResources" is expecting an hibernate xml mapping file.
See# http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/LocalSessionFactoryBean.html#setMappingResources%28java.lang.String[]%29
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, or since you are using Hibernate/JPA annotations, the factoryBean has a property for "packagesToScan" which scans those packages for Annotated classes, there is also another property to use to list out the classes I forget what it was called, probably "mappedClasses"

I prefer to use the packagesToScan since that list will be smaller than the list in mappedClasses.

Mark
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code you're trying to run is a Tutorial from com.vaannila so, I think it missing something or not fully configured.

Try the solution below...hope it help.





Here is an example:



From the example above, you can make it works.
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tommy, he is not using xml mapping, he is using Annotation mapping. So you example will not work for him. He is just setting the wrong property in the AnnotationSessionFactoryBean.

Mark
 
Tommy Delson
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:Tommy, he is not using xml mapping, he is using Annotation mapping. So you example will not work for him. He is just setting the wrong property in the AnnotationSessionFactoryBean.

Mark




Well, based on the exception "Caused by: org.springframework.beans.NotWritablePropertyException:
Invalid property 'mappingResources' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]:
Bean property 'mappingResources' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?"

I can tell that "mappingResources" is not proper configured, the app looking for a resources, but it can not find due not configure correctly. Whether using Annotation mapping or not doesn't matter since, the error indicated at configuration level not application level error.

If you look carefully and check Spring document you'll find out the "mappingResources" is not configured correctly.

You can recreate the problem and confirm, I'll try and see if that's the problem or there are other problems.


@ali honarmand
Could you tell what's your status and did you get the problem solved?

 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tommy Delson wrote:

Mark Spritzler wrote:Tommy, he is not using xml mapping, he is using Annotation mapping. So you example will not work for him. He is just setting the wrong property in the AnnotationSessionFactoryBean.

Mark




Well, based on the exception "Caused by: org.springframework.beans.NotWritablePropertyException:
Invalid property 'mappingResources' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]:
Bean property 'mappingResources' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?"

I can tell that "mappingResources" is not proper configured, the app looking for a resources, but it can not find due not configure correctly. Whether using Annotation mapping or not doesn't matter since, the error indicated at configuration level not application level error.

If you look carefully and check Spring document you'll find out the "mappingResources" is not configured correctly.

You can recreate the problem and confirm, I'll try and see if that's the problem or there are other problems.


@ali honarmand
Could you tell what's your status and did you get the problem solved?



Yes, but he shouldn't even be setting or using the mappingResource property in his configuration. He needs to remove it and use the correct property.

Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic