[Hibernate | Spring ] Configuration de fichier Spring
Hello les jeunes (lol),
je retouche une application en Spring et je dois mettre une couche hibernate, j'ai le problème suivant :
on a des Trainings (formations) initialisés dans le fichier applicationContext.xml suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
<bean id="training" singleton="false"
class="fr.model.hibernate.Training">
<property name="details">
<map>
<entry key="fr"><ref local="trainingdetail"/></entry>
</map>
</property>
</bean>
<bean id="trainingdetail" singleton="false"
class="fr.model.hibernate.TrainingDetail">
<property name="language" value="fr"/>
</bean> |
En gros , une classe Training contient une map "details" qui a pour clé : la langue (fr par défaut) et pour valeur un "trainingDetail" (detail de la formation/training).
L'objet trainingDetail a pour propriété "language" (on verra par la suite..).
Pour résumer, dans ma Base de donnée, j'obtiens 2 tables :
" training"
et
"trainingDetail" qui possède une clé etrangère qui est l'id du training :. (classique) id_training
Dans ma classe Training, jai la méthode :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
public class Training {
/**
* @param detail A Detail to add.
*/
public void addDetail(ITrainingDetail detail)
{
detail.setTraining(this);
details.put(detail.getLanguage(), detail);
}
} |
En gros, à chaque fois que je souhaite ajouter un trainingDetail, ben avant l'ajout, je lui indique quel est son Training (car les associations ne sont pas managées sous Hibernate, fo bien indiquer le "père" de l'association) pour ne pas avoir un id_training qui est à NULL dans la BD en gros.
Le problème que je rencontre est que ça marche pas pour le trainingDetail qui existe par défaut (j'ai un id_training = NULL dans la BD en gros)
donc j'imerais savoir s'il est possible en gros de faire sous Spring un truc du genre :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
<bean id="training" singleton="false"
class="fr.model.hibernate.Training">
<property name="details">
<map>
<entry key="fr"><ref local="trainingdetail"/></entry>
</map>
</property>
</bean>
<bean id="trainingdetail" singleton="false"
class="fr.model.hibernate.TrainingDetail">
<property name="language" value="fr"/>
<property name="training" value="l'objet training qui va le contenir"/>
</bean> |
Je débute sous Spring, lol si quelqu'un pouvait m'aider ce serait certes sympathoche :D
thanx :roll: !