الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

دمج Hibernate + Spring

بدأه BlackBeard في 18 أغسطس 2011 · 13 رد · 1,723 مشاهدة · في JavaEE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم و رحمة الله تعالى و بركاته

رمضان مبارك

أريد إنشاء تطبيق ويب بستعمال Hibernate with Spring

قمت بإعداد ملف الإعدادات الخاص ب Spring و هذا مقطع منه و هو المقصود من مشكلتي

<!-- Hibernate SessionFactory Definition -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<!--
		<property name="namingStrategy">
        	<ref bean="namingStrategy"/>
    	</property>
		-->
		<property name="annotatedClasses">
  			<list>
				<value>entites.gestion.Configuration</value>
  			</list>
		</property><!-- -->
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">true</prop>
				<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
				<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
			</props>
		</property>
		<property name="dataSource" ref="myDataSource" />
	</bean><!-- -->

لكن عند طلب إنشاء هذه الحبيبة لا يتم ذلك و يظهر لي هذا الخطئ

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'annotatedClasses' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.NotWritablePropertyException: Invalid property 'annotatedClasses' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:670)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:572)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:737)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:764)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:753)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1061)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
	at Main.Main.main(Main.java:19)

أرجو أن أكون أوظحت مشكلتي

شكرا

showimagephp.jpg

#2

من أين حصلت على ملف ال xml هذا ؟

#3

لقد قمت بتركيبه من عدة أمثلة

showimagephp.jpg

#4

ممكن ترد على هذا السؤال؟

Bean property 'annotatedClasses' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?

ما نوع هذه ال property في الكود عندك ؟

#5
هويدي كتب:

ممكن ترد على هذا السؤال؟

Bean property 'annotatedClasses' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?

ما نوع هذه ال property في الكود عندك ؟

السلام عليكم

لقد قمت بالتحقق من الفئة و وجدتها لا تعمل إلا مع ملفات XML HBM التي تصف ال POJOs لذلك قمت باستبدالها بهذه الفئة

org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean

لكن لم تصلح معي وظهر لي نفس الخطئ مع أنها تحتوي على setter الخاص بال property

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'annotatedClasses' of bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.NotWritablePropertyException: Invalid property 'annotatedClasses' of bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:670)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:572)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:737)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:764)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:753)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1061)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
	at Main.Main.main(Main.java:22)
showimagephp.jpg

#7

مشكور أخ هويدي على الرابط

لكني أنا استعملت في برنامجي ال Annotaions ولم أستخدم ال hbm files هل من حل لمشكلتي لا أظن أنها في التغيير من Annotation إلى ال hbm files ؟

احترت معها confused_smile.gif

شكرا

showimagephp.jpg

#8

في الحقيقه لم أتعامل مع Hbnt+Spring منذ فتره طويييله ...

حاول أيجاد tutorial و طبقه بحذافيره ..

#9

يا أخي تعبت جربت هل رأيت كيفية استعمال هده الفئة

لا أظن أنني قد أخطأت في شيئ

http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.html

آسف لأني أخطأت في الرابط السابق

تم تعديل هذه المشاركة بواسطة BlackBeard في 19 أغسطس 2011 في 19:24

showimagephp.jpg

#10
هويدي كتب:

ما رأيك لو تجرب هذا ال tutorial ...

http://www.javabeat....-framewo-2.html

السلام عليكم

لقد قمت بتجربته و ها هي النتيجة confused_smile.gifmad.gifblink.gif

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeDao' defined in file [C:\MyFolderS\workspaceJ2EE\example\spring-hibernate.xml]: Cannot resolve reference to bean 'hibernateTemplate' while setting bean property 'hibernateTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in file [C:\MyFolderS\workspaceJ2EE\example\spring-hibernate.xml]: Cannot resolve reference to bean 'mySessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in file [C:\MyFolderS\workspaceJ2EE\example\spring-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'dataSource' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in file [C:\MyFolderS\workspaceJ2EE\example\spring-hibernate.xml]: Cannot resolve reference to bean 'mySessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in file [C:\MyFolderS\workspaceJ2EE\example\spring-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'dataSource' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in file [C:\MyFolderS\workspaceJ2EE\example\spring-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'dataSource' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'dataSource' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:670)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:572)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:737)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:764)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:753)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1061)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1046)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1046)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
	at dao.SpringHibernateTest.main(SpringHibernateTest.java:24)
showimagephp.jpg

#11

هل من مثال عن كود مصدري مضمون أنه يعمل به كل المكتيات فقط لكي أقطع الشك باليقين ؟

showimagephp.jpg

#12

إرجع إلى توثيق Spring ..

#13

لكن ما هو السبب بالظبط في هذا الخطئ ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟huh.gif

showimagephp.jpg

#14
BlackBeard كتب:

لكن ما هو السبب بالظبط في هذا الخطئ ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟huh.gif

تم و الحمد لله حل المشكلة بنجاح

و ها هي أسباب المشكلة

- وجود إصدارين للمنصة Spring إحداها القديم و الذي كان مخفي في المجلد C:\Program Files\Java\jre6\lib\ext و المتسبب هو أنا و ضعتها من مدة و نسيتها blush.giflaugh.gif

- أما الثاني و عدم كتابة الحرف & "AnnotaionSessionFactoryBean&"

شكرا

1
showimagephp.jpg

مواضيع مشابهة