-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: probleme pour genere une id d une table qui ne contient pas
PostPosted: Mon Feb 16, 2009 12:35 pm 
Regular
Regular

Joined: Wed Jan 28, 2009 8:31 pm
Posts: 54
Hello I will like to map a table that doesn t have a primary key
So there is no id column and no values


d'apres la faq java.developpez.com/faq/hibernate
s est possible avec
Code:
<id
   column="nomColumn"
   name="unNom"
   type="LeType"
>
   <generator class="assigned" />
</id>



Donc je l ai code et j’obtiens une erreur
Quote:
11:18:48,705 DEBUG QueryTranslator:207 - HQL: select from ca.canassistance.pojo.AvinfogePojo as base where base.noDossier = ?
11:18:48,705 DEBUG QueryTranslator:208 - SQL: select avinfogepo0_.ID as ID, avinfogepo0_.IG_ID_DOUBLE_ASS as IG_ID_DO2_, avinfogepo0_.IG_DT_EVENEMENT as IG_DT_EV3_, avinfogepo0_.IG_GROUPE_CLIENT as IG_GROUP4_, avinfogepo0_.IG_NO_DOSSIER as IG_NO_DO5_, avinfogepo0_.IG_NO_CERTIFICAT_SAM as IG_NO_CE6_, avinfogepo0_.IG_NO_CERTIFICAT as IG_NO_CE7_, avinfogepo0_.IG_NO_GROUPE as IG_NO_GR8_, avinfogepo0_.IG_ID_USER as IG_ID_USER, avinfogepo0_.IG_DT_MODIF as IG_DT_M10_, avinfogepo0_.IG_ID_ACCIDENT as IG_ID_A11_ from AVINFOGE avinfogepo0_ where (avinfogepo0_.IG_NO_DOSSIER=? )
11:18:48,705 DEBUG BatcherImpl:204 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:18:48,705 DEBUG SQL:230 - select avinfogepo0_.ID as ID, avinfogepo0_.IG_ID_DOUBLE_ASS as IG_ID_DO2_, avinfogepo0_.IG_DT_EVENEMENT as IG_DT_EV3_, avinfogepo0_.IG_GROUPE_CLIENT as IG_GROUP4_, avinfogepo0_.IG_NO_DOSSIER as IG_NO_DO5_, avinfogepo0_.IG_NO_CERTIFICAT_SAM as IG_NO_CE6_, avinfogepo0_.IG_NO_CERTIFICAT as IG_NO_CE7_, avinfogepo0_.IG_NO_GROUPE as IG_NO_GR8_, avinfogepo0_.IG_ID_USER as IG_ID_USER, avinfogepo0_.IG_DT_MODIF as IG_DT_M10_, avinfogepo0_.IG_ID_ACCIDENT as IG_ID_A11_ from AVINFOGE avinfogepo0_ where (avinfogepo0_.IG_NO_DOSSIER=? )
11:18:48,705 DEBUG BatcherImpl:253 - preparing statement
11:18:48,768 DEBUG StringType:46 - binding '5814' to parameter: 1
11:18:48,799 DEBUG JDBCExceptionReporter:49 - SQL Exception
java.sql.SQLException: ORA-00904: "AVINFOGEPO0_"."ID": invalid identifier

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1037)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1132)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3316)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3361)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:89)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:880)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:273)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1063)
at net.sf.hibernate.loader.Loader.list(Loader.java:1054)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1554)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:49)
at ca.canassistance.model.dao.AvinfogeDAO.find(AvinfogeDAO.java:189)
at ca.canassistance.service.AvingogeServicePersistance.existAvinfogeCle(AvingogeServicePersistance.java:50)
at ca.canassistance.batch.MettreJourInfogene.creerInfogene(MettreJourInfogene.java:238)
at ca.canassistance.batch.MettreJourInfogene.traiterFichier(MettreJourInfogene.java:224)
at ca.canassistance.batch.MettreJourInfogene.traiter(MettreJourInfogene.java:184)
at ca.canassistance.batch.MettreJourInfogene.<init>(MettreJourInfogene.java:142)
at ca.canassistance.batch.MettreJourInfogene.main(MettreJourInfogene.java:839)
11:18:48,799 WARN JDBCExceptionReporter:57 - SQL Error: 904, SQLState: 42000
11:18:48,799 ERROR JDBCExceptionReporter:58 - ORA-00904: "AVINFOGEPO0_"."ID": invalid identifier

11:18:48,799 DEBUG BatcherImpl:211 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:18:48,799 DEBUG BatcherImpl:275 - closing statement
11:18:48,814 DEBUG JDBCExceptionReporter:49 - Could not execute query
java.sql.SQLException: ORA-00904: "AVINFOGEPO0_"."ID": invalid identifier

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1037)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1132)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3316)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3361)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:89)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:880)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:273)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1063)
at net.sf.hibernate.loader.Loader.list(Loader.java:1054)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1554)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:49)
at ca.canassistance.model.dao.AvinfogeDAO.find(AvinfogeDAO.java:189)
at ca.canassistance.service.AvingogeServicePersistance.existAvinfogeCle(AvingogeServicePersistance.java:50)
at ca.canassistance.batch.MettreJourInfogene.creerInfogene(MettreJourInfogene.java:238)
at ca.canassistance.batch.MettreJourInfogene.traiterFichier(MettreJourInfogene.java:224)
at ca.canassistance.batch.MettreJourInfogene.traiter(MettreJourInfogene.java:184)
at ca.canassistance.batch.MettreJourInfogene.<init>(MettreJourInfogene.java:142)
at ca.canassistance.batch.MettreJourInfogene.main(MettreJourInfogene.java:839)
11:18:48,814 WARN JDBCExceptionReporter:57 - SQL Error: 904, SQLState: 42000
11:18:48,814 ERROR JDBCExceptionReporter:58 - ORA-00904: "AVINFOGEPO0_"."ID": invalid identifier

11:18:49,968 DEBUG JDBCTransaction:82 - rollback
11:18:49,983 DEBUG SessionImpl:596 - transaction completion
11:18:50,591 DEBUG SessionImpl:578 - closing session
11:18:50,591 DEBUG SessionImpl:3383 - disconnecting session
11:18:50,591 DEBUG DriverManagerConnectionProvider:120 - returning connection to pool, pool size: 1
11:18:50,591 DEBUG SessionImpl:596 - transaction completion
net.sf.hibernate.exception.SQLGrammarException: Could not execute query
at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:69)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4131)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1557)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:49)
at ca.canassistance.model.dao.AvinfogeDAO.find(AvinfogeDAO.java:189)
at ca.canassistance.service.AvingogeServicePersistance.existAvinfogeCle(AvingogeServicePersistance.java:50)
at ca.canassistance.batch.MettreJourInfogene.creerInfogene(MettreJourInfogene.java:238)
at ca.canassistance.batch.MettreJourInfogene.traiterFichier(MettreJourInfogene.java:224)
at ca.canassistance.batch.MettreJourInfogene.traiter(MettreJourInfogene.java:184)
at ca.canassistance.batch.MettreJourInfogene.<init>(MettreJourInfogene.java:142)
at ca.canassistance.batch.MettreJourInfogene.main(MettreJourInfogene.java:839)
Caused by: java.sql.SQLException: ORA-00904: "AVINFOGEPO0_"."ID": invalid identifier

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1037)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1132)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3316)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3361)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:89)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:880)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:273)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1063)
at net.sf.hibernate.loader.Loader.list(Loader.java:1054)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1554)
... 8 more



Donc j’aimerai bien hibernate génère des valeurs de clé primaire pour les valeurs
Déjà dans la table et incrémente les nouvelles valeurs.


Last edited by chady on Mon Feb 16, 2009 6:16 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2009 12:58 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
I am not quite sure, what you really want. But actually it is not possible to map a table without primary key.

Your exception looks like you have a primary key in your mapping. Could you post your mapping, your entity-class and your testclass?

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2009 1:13 pm 
Regular
Regular

Joined: Wed Jan 28, 2009 8:31 pm
Posts: 54
my hbm
Code:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="pojo">
   <class
      name="AvinfogePojo"
      table="AVINFOGE"
   >
   
      [b]<id
         name="id"
         type="integer"
         column="ID"
      >
         <generator class="assigned" />

      </id>[/b]
      <property
         name="doubleAss"
         column="IG_ID_DOUBLE_ASS"
         type="string"
         not-null="false"
         length="1"
      />
      <property
         name="dtEvenement"
         column="IG_DT_EVENEMENT"
         type="integer"
         not-null="false"
         length="8"
      />
      <property
         name="groupeClient"
         column="IG_GROUPE_CLIENT"
         type="string"
         not-null="false"
         length="8"
      />
      <property
         name="noDossier"
         column="IG_NO_DOSSIER"
         type="string"
         not-null="false"
         length="6"
      />
      <property
         name="noCertificatSam"
         column="IG_NO_CERTIFICAT_SAM"
         type="string"
         not-null="false"
         length="20"
      />
      <property
         name="noCertificat"
         column="IG_NO_CERTIFICAT"
         type="string"
         not-null="false"
         length="10"
      />
      <property
         name="noGroupe"
         column="IG_NO_GROUPE"
         type="string"
         not-null="false"
         length="6"
      />
      <property
         name="idUser"
         column="IG_ID_USER"
         type="string"
         not-null="false"
         length="4"
      />
      <property
         name="dtModif"
         column="IG_DT_MODIF"
         type="integer"
         not-null="false"
         length="8"
      />
      <property
         name="idAccident"
         column="IG_ID_ACCIDENT"
         type="string"
         not-null="false"
         length="1"
      />


   </class>
</hibernate-mapping>


and my class pojo
Code:

package pojo;

import java.io.Serializable;
import java.util.List;

import net.sf.hibernate.HibernateException;
import ca.canassistance.model.Avinfoge;
import ca.canassistance.model.dao.AvinfogeDAO;

/**
* This class has been automatically generated by Hibernate Synchronizer. For
* more information or documentation, visit The Hibernate Synchronizer page at
* http://www.binamics.com/hibernatesync or contact Joe Hudson at
* joe@binamics.com.
*
* This is an object that contains data related to the AVINFOGE table. Do not
* modify this class because it will be overwritten if the configuration file
* related to this class is modified.
*
* @hibernate.class table="AVINFOGE"
*/
public class AvinfogePojo implements Serializable {

   /**
    *
    */
   private static final long serialVersionUID = -2444185467393453780L;

//    fields
   private String doubleAss;
   private Integer dtEvenement;
   private String groupeClient;
   private String noDossier;
   private String noCertificatSam;
   private String noCertificat;
   private String noGroupe;
   private String idUser;
   private Integer dtModif;
   private String idAccident;
   [b]private Integer id;[/b]
   private AvinfogeDAO dao;

   // constructors
   public AvinfogePojo(Integer id,String doubleAss, Integer dtEvenement,
         String groupeClient, String noDossier, String noCertificatSam,
         String noCertificat, String noGroupe, String idUser,
         Integer dtModif, String idAccident) {
      
       this.setId(id);
        this.setDoubleAss(doubleAss);
        this.setIdUser(idUser);
        this.setDtEvenement(dtEvenement);
        this.setNoCertificat(noCertificat);
        this.setNoDossier(noDossier);
        this.setNoGroupe(noGroupe);
      this.setGroupeClient(groupeClient);
      this.setNoCertificatSam(noCertificatSam);
   
      this.setDtModif(dtModif);
      this.setIdAccident(idAccident);
   

   }

   public AvinfogePojo() {
      initialize();
   }

/*   public AvinfogePojo(Avinfoge avinfoge) {
      this.setDoubleAss(doubleAss);
        this.setIdUser(idUser);
        this.setDtEvenement(dtEvenement);
        this.setNoCertificat(noCertificat);
        this.setNoDossier(noDossier);
        this.setNoGroupe(noGroupe);
      
        this.setDtModif(avinfoge.getIdMotif());
      this.setGroupeClient(avinfoge.getGroupeClient());
      this.setIdAccident(avinfoge.getIdAccident());
      this.setNoCertificatSam(avinfoge.getNoCertificatSam());
      // avinfoge.getn

   }*/

   protected void initialize() {
   }

   public static long getSerialVersionUID() {
      return serialVersionUID;
   }

   public Integer getDtEvenement() {
      return dtEvenement;
   }

   public void setDtEvenement(Integer dtEvenement) {
      this.dtEvenement = dtEvenement;
   }

   public Integer getDtModif() {
      return dtModif;
   }

   public void setDtModif(Integer dtModif) {
      this.dtModif = dtModif;
   }

   public String getGroupeClient() {
      return groupeClient;
   }

   public void setGroupeClient(String groupeClient) {
      this.groupeClient = groupeClient;
   }

   public Integer getId() {
      return id;
   }

   public void setId(Integer id) {
      this.id = id;
   }

   public String getIdAccident() {
      return idAccident;
   }

   public void setIdAccident(String idAccident) {
      this.idAccident = idAccident;
   }



   public String getNoCertificat() {
      return noCertificat;
   }

   public void setNoCertificat(String noCertificat) {
      this.noCertificat = noCertificat;
   }

   public String getNoCertificatSam() {
      return noCertificatSam;
   }

   public void setNoCertificatSam(String noCertificatSam) {
      this.noCertificatSam = noCertificatSam;
   }

   public String getNoDossier() {
      return noDossier;
   }

   public void setNoDossier(String noDossier) {
      this.noDossier = noDossier;
   }

   public String getNoGroupe() {
      return noGroupe;
   }

   public void setNoGroupe(String noGroupe) {
      this.noGroupe = noGroupe;
   }

   
   public String getDoubleAss() {
      return doubleAss;
   }

   public void setDoubleAss(String doubleAss) {
      this.doubleAss = doubleAss;
   }

   [b]public String getIdUser() {
      return idUser;
   }

   public void setIdUser(String idUser) {
      this.idUser = idUser;
   }[/b]
   public boolean estDansLaBase(String cleDossier) throws HibernateException {
      if (dao == null)
         this.setDao(new AvinfogeDAO());
      List l = this.getDao().find(cleDossier);
      if (l != null)
         return true;
      return false;

   }

   public AvinfogeDAO getDao() {
      return dao;
   }

   public void setDao(AvinfogeDAO dao) {
      this.dao = dao;
   }

   @Override
   public int hashCode() {
      final int PRIME = 31;
      int result = 1;
      result = PRIME * result
            + ((doubleAss == null) ? 0 : doubleAss.hashCode());

      result = PRIME * result + ((dtModif == null) ? 0 : dtModif.hashCode());
      result = PRIME * result
            + ((groupeClient == null) ? 0 : groupeClient.hashCode());
      result = PRIME * result + ((id == null) ? 0 : id.hashCode());
      result = PRIME * result
            + ((idAccident == null) ? 0 : idAccident.hashCode());
      result = PRIME * result + ((idUser == null) ? 0 : idUser.hashCode());

      result = PRIME * result
            + ((noCertificatSam == null) ? 0 : noCertificatSam.hashCode());

      return result;
   }

   @Override
   public boolean equals(Object obj) {
      if (this == obj)
         return true;
      if (obj == null)
         return false;
      if (getClass() != obj.getClass())
         return false;
      final AvinfogePojo other = (AvinfogePojo) obj;
      if (dao == null) {
         if (other.dao != null)
            return false;
      } else if (!dao.equals(other.dao))
         return false;
      if (doubleAss == null) {
         if (other.doubleAss != null)
            return false;
      } else if (!doubleAss.equals(other.doubleAss))
         return false;

      if (dtModif == null) {
         if (other.dtModif != null)
            return false;
      } else if (!dtModif.equals(other.dtModif))
         return false;
      if (groupeClient == null) {
         if (other.groupeClient != null)
            return false;
      } else if (!groupeClient.equals(other.groupeClient))
         return false;
      if (id == null) {
         if (other.id != null)
            return false;
      } else if (!id.equals(other.id))
         return false;
      if (idAccident == null) {
         if (other.idAccident != null)
            return false;
      } else if (!idAccident.equals(other.idAccident))
         return false;
      if (idUser == null) {
         if (other.idUser != null)
            return false;
      } else if (!idUser.equals(other.idUser))
         return false;

      if (noCertificatSam == null) {
         if (other.noCertificatSam != null)
            return false;
      } else if (!noCertificatSam.equals(other.noCertificatSam))
         return false;

      return true;
   }

}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 4:12 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
You need an ID-column in your database, as you mapped a column named "ID". If you are not able to change the database, use a composite primary key.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.