Erreur MySQL suite au mapping d'une collection
Bonjour,
Voila, j'ai un objet Contact qui possède une liste (un HashSet) de Phone.
Utilisation standard d'hibernate, je cherche à ajouter un Phone à mon Contact de la façon suivante :
Code:
1 2 3 4 5 6
|
//Recup du bean par Spring
IContactDao dao = (IContactDao) new XmlBeanFactory(new ClassPathResource("applicationContext.xml")).getBean("dao");
Phone phone = new Phone("06.25.45.49.12");
Contact contact1 = dao.getContactById(1);
contact1.getPhones().add(phone); |
Sauf qu'à l'execution j'obtiens l'erreur MySQL suivante
Code:
1 2 3 4
|
ATTENTION: SQL Error: 1054, SQLState: 42S22
8 juin 2007 09:52:30 org.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: Unknown column 'phones1_.phone' in 'field list' |
Mes 2 mapping :
Contact.hbm.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
<hibernate-mapping package="entities">
<class name="Contact" table="contacts" lazy="false">
<id name="id" column="id">
<generator class="increment"></generator>
</id>
<property name="nom" />
<property name="prenom" />
<property name="surnom" />
<property name="birthDate" />
<property name="adresse" />
<property name="codePostal" />
<property name="city" />
<set name="phones"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
order-by="description asc"
outer-join="true" >
<cache usage="read-write" />
<key column="id"></key>
<one-to-many class="entities.Phone" />
</set>
</class>
</hibernate-mapping> |
Phone.hbm.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
<hibernate-mapping package="entities">
<class name="Phone" table="phones" lazy="false">
<id name="id" column="id">
<generator class="increment"></generator>
</id>
<property name="phone" />
<many-to-one name="contact" class="entities.Contact"
cascade="none" outer-join="auto" update="true" insert="true"
column="id_contact" />
</class>
</hibernate-mapping> |
et mes 2 tables dans MySQL :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
CREATE TABLE `contacts`
(`id` int(3) NOT NULL,
`nom` varchar(25) default NULL,
`prenom` varchar(25) default NULL,
`surnom` varchar(25) default NULL,
`birthdate` date default NULL,
`adresse` varchar(150) default NULL,
`codePostal` int(11) default NULL,
`city` varchar(50) default NULL,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `phones`
(`id` int(3) NOT NULL,
`phone_number` varchar(14) NOT NULL,
`id_contact` int(3) NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_phone_contact` (`id_contact`),CONSTRAINT `fk_phone_contact` FOREIGN KEY (`id_contact`) REFERENCES `contacts` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION )
ENGINE=InnoDB DEFAULT CHARSET=latin1; |
Je n'arrive pas du tout a localiser d'où pourrait provenir l'erreur, d'où provient ce phone1_.phone ?