[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - assigning a column as an id for persisting

Jihnd do-not-reply at jboss.com
Thu Jan 17 08:14:35 EST 2008


hello all,

i'm trying to create a new record in an oracle xe database using webservices, entity and session beans. i get the error 
"Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():" when i try to create the record however. 

i have annotated a column with the id value but when i try to create the record, it doesnt seem to recognise that?

here are my classes for clarity:

package domain;
  | 
  | import javax.persistence.*;
  | import org.jboss.web.WebService;
  | import org.jboss.wsf.spi.*;
  | import org.jboss.wsf.spi.annotation.WebContext;
  | 
  | @Entity
  | @Table(name="Audiorec")
  | @WebContext(contextRoot="/AVmanBean")
  | public class Audiorec implements java.io.Serializable{
  |     private int Barcode_audiorec;
  |     private String Audiorec_alias;
  |     private String Serial_audiorec;
  |     private String Media_audiorec;
  |     private String Formats_audiorec;
  | 
  |     public Audiorec() {
  |     }
  | 
  | 
  |     public Audiorec(String Alias, Integer Barcode, String Model, String Serial, String Media, String Formats, String Inputs, String Outputs) {
  |     super();
  |     this.Audiorec_alias = Alias;
  |     this.Barcode_audiorec = Barcode;
  |     this.Serial_audiorec = Serial;
  | }
  | 
  |     @Id
  |     @Column(name="Audiorec_alias")
  |     public String getAudiorec_alias( ) { return Audiorec_alias; }
  |     public void setAudiorec_alias(String alias) { this.Audiorec_alias = alias; }
  | 
  |     @Column(name="Barcode_audiorec")
  |     public int getBarcode_audiorec( ) { return Barcode_audiorec; }
  |     public void setBarcode_audiorec(int barcode) { this.Barcode_audiorec = barcode; }
  | 
  |     @Column(name="Serial_audiorec")
  |     public String getSerial_audiorec( ) { return Serial_audiorec; }
  |     public void setSerial_audiorec(String serial) { this.Serial_audiorec = serial; }
  | 
  |     @Column(name="Media_audiorec")
  |     public String getMedia_audiorec( ) { return Media_audiorec; }
  |     public void setMedia_audiorec(String media) { this.Media_audiorec = media; }
  | 
  |     @Column(name="Formats_audiorec")
  |     public String getFormats_audiorec( ) { return Formats_audiorec; }
  |     public void setFormats_audiorec(String formats) { this.Formats_audiorec = formats; }
  | 
  | }

and my session bean:

package Audiorec;
  | 
  | import javax.ejb.Stateless;
  | import javax.jws.WebMethod;
  | import javax.jws.WebParam;
  | import javax.persistence.EntityManager; 
  | 
  | import javax.persistence.PersistenceContext;
  | 
  | import domain.Audiorec;
  | import javax.ejb.TransactionAttribute;
  | import javax.ejb.TransactionAttributeType;
  | import org.jboss.ws.annotation.*;
  | import javax.jws.WebService;
  | import org.jboss.wsf.spi.annotation.WebContext;
  | 
  | @Stateless
  | @WebService(name="AVmanBean", serviceName="AVmanBean")
  | //@WebContext(contextRoot="/AVmanBean")
  | public class AVmanBean implements AVmanRemote{
  |     @PersistenceContext 
  | (unitName="AVmanBean")
  | private EntityManager manager;
  | 
  |     @TransactionAttribute(TransactionAttributeType.REQUIRED)
  |     public void createAudiorec(@WebParam(name = "Alias")
  | String Alias, @WebParam(name = "barcode")Integer Barcode, @WebParam(name = "serial")String Serial, @WebParam(name = "media")String Media)  
  |     {
  |         Audiorec audiorec = new Audiorec();
  |         audiorec.setAudiorec_alias(Alias);
  |         audiorec.setBarcode_audiorec(Barcode);
  |         audiorec.setSerial_audiorec(Serial);
  |         audiorec.setMedia_audiorec(Media);
  |     
  |         manager.persist(audiorec);
  |     }
  | 
  |     public String findAudiorec(@WebParam(name = "Audiorec_alias")
  |     String alias) {
  |        Audiorec arrr = manager.find(Audiorec.class, alias);
  |        return arrr.getSerial_audiorec();
  |     }
  | 
  |   
  | }

i am able to search records through my webservices so i'm hoping nothing's majorly out of place but i'm a bit stumped on this id thing. i'm reading up on hibernate right now but i thought i'd just throw it out here if anyone could steer me in the right direction

cheers for reading thus far :)

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4120861#4120861

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4120861



More information about the jboss-user mailing list