clé primaire composé et persistence.xml
Bonjour à tous
J'ai dans mon projet une table qui possède une clé primaire composé de 2 champs.
class : DatasetLocus
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 30 31 32 33 34 35 36 37 38 39 40
|
package sagacity.entity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
@Entity
@IdClass(DatasetLocusPk.class)
public class DatasetLocus implements Serializable{
private static final long serialVersionUID = 1L;
@Id
private long dataset_id;
@Id
private String locusId;
/*getters setters*/
public long getDataset_id() {
return dataset_id;
}
public void setDataset_id(long dataset_id) {
this.dataset_id = dataset_id;
}
public String getLocus() {
return locusId;
}
public void setLocus(String locus) {
this.locusId = locus;
}
} |
class : DatasetLocusPk
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
package sagacity.entity;
import java.io.Serializable;
// class permettant de créer la clé composée de la class DatasetLocus
public class DatasetLocusPk implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private long datasetId;
private String locusId;
public DatasetLocusPk() {
}
public DatasetLocusPk(long datasetId, String locusId) {
this.datasetId = datasetId;
this.locusId = locusId;
}
@Override
public int hashCode() {
return (datasetId+locusId).hashCode();
}
@Override
public boolean equals(Object obj) {
/*
* vérification de l'egalite des références, on compare l'objet avec lui
* meme ...
*/
if (obj == this) {
return true;
}
/* On vérifie ensuite si le type des variables(objet) sont les memes */
if (obj instanceof DatasetLocusPk) {
DatasetLocusPk dl = (DatasetLocusPk) obj;
if (this.datasetId != dl.datasetId) {
return false;
}
if (dl.locusId == null
|| !this.equals(((DatasetLocusPk) obj).locusId)) {
return false;
}
return true;
}
return false;
}
/* getters setters */
public long getDatasetId() {
return datasetId;
}
public void setDatasetId(long datasetId) {
this.datasetId = datasetId;
}
public String getLocus() {
return locusId;
}
public void setLocus(String locus) {
this.locusId = locus;
}
} |
et dans le fichier persistence.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
|
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="sagacityPU">
<jta-data-source>bdd</jta-data-source>
<class>sagacity.entity.DatasetLocusPK</class>
<class>sagacity.entity.DatasetLocus</class>
<properties>
<property name="toplink.logging.level" value="FINE" />
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/sagacity" />
<property name="toplink.jdbc.user" value="root" />
<property name="toplink.jdbc.password" value="mysql" />
<property name="toplink.ddl-generation" value="drop-and-create-tables" />
</properties>
</persistence-unit>
</persistence> |
je me retrouve avec une erreur me disant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
Buildfile: C:\Documents and Settings\Stagiaire_2009\Bureau\eclipse-SDK-3.4.2-win32\workspace\.metadata\.plugins\org.eclipse.jst.server.generic.core\serverdef\sunappsrv-ant.xml
deploy.j2ee.ear:
[jar] Building jar: C:\Documents and Settings\Stagiaire_2009\Bureau\eclipse-SDK-3.4.2-win32\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\sagacity.ear
tools:
deploy:
[exec] CLI171 Command deploy failed : Deploying application in domain failed; sagacity/entity/DatasetLocusPK (wrong name: sagacity/entity/DatasetLocusPk)
deploy-url-message:
[echo] Application Deployed at: http://localhost:8081/sagacity
BUILD SUCCESSFUL
Total time: 5 seconds |
Ou doit se mettre la classe qui représente la clé primaire composé ?
Merci