-->
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.  [ 1 post ] 
Author Message
 Post subject: Id generation is not working
PostPosted: Thu Dec 07, 2006 9:53 am 
Newbie

Joined: Wed May 04, 2005 9:34 am
Posts: 16
Location: Germany
Hi,

it´s probably a very simple problem, but i can´t solve it.

I have a simple object mapped to a database-table. There are no relationships to other objects. I mapped the object via Annotations. Here is my Object-Class:

Code:
package de.gebit.geplan.datastructures.data;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Index;

@Entity
@Table(name="S_Benutzer",
   uniqueConstraints = {@UniqueConstraint(columnNames={"b_nr"})})
@org.hibernate.annotations.Table(appliesTo="S_Benutzer", indexes={@Index(name="b_nr", columnNames={"b_nr"})})
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@AccessType("property")
public class GeplanBenutzerDAO implements Serializable, IBenutzerDAO {
   private static final long serialVersionUID = 1L;
   private Long id;
   private String name;
   private String vorname;
   private int art;
   private String kennung;
   private String passwort;
   private int sperre;
   private int standard;
      
   public GeplanBenutzerDAO() {}
      
   @Id 
   @GeneratedValue(strategy=GenerationType.AUTO)
   @Column(name="b_nr", nullable=false, unique=true, length=4)
   public Long getId() {
      return id;
   }

   @Basic
   @Column(name="b_name", length=200)
   public String getName() {
      return name;
   }

   @Basic
   @Column(name="b_vname", length=200)
   public String getVorname() {
      return vorname;
   }

   @Basic
   @Column(name="b_kenn", length=200)
   public String getKennung() {
      return kennung;
   }

   @Basic
   @Column(name="b_passwort", length=200)
   public String getPasswort() {
      return passwort;
   }

   @Basic
   @Column(name="b_art", length=2)
   public int getArt() {
      return art;
   }

   @Basic
   @Column(name="b_sperre", length=200)
   public int getSperre() {
      return sperre;
   }

   @Basic
   @Column(name="b_standard", length=2)
   public int getStandard() {
      return standard;
   }

   public void setId(Long id) {
      this.id=id;
   }
   
   public void setName(String name) {
      this.name=name;
   }

   public void setVorname(String name) {
      this.vorname=name;
   }

   public void setKennung(String kennung) {
      this.kennung=kennung;
   }

   public void setPasswort(String passwort) {
      this.passwort=passwort;
   }

   public void setArt(int art) {
      this.art=art;
   }
   
   public void setSperre (int sperre) {
      this.sperre=sperre;
   }

   public void setStandard(int pass_change) {
      this.standard=pass_change;
   }

   public int compareTo(Object o) {
      return this.getId().compareTo(((GeplanBenutzerDAO)o).getId());
   }
}


When i create a new object and try to save it to the database, i got an error saying that null can not be inserted into field "b_nr". So the problem is that the id-field is not created correctly. What´s wrong with my approach and how can i fix it. "b_nr" is a numeric field and i just want him to take the next free number.

Thanks for any help.
Christoph

Hibernate version: 3.2.1

Name and version of the database you are using: Oracle 9i, MS SQL-Server 7.0


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

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.