-->
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.  [ 5 posts ] 
Author Message
 Post subject: "ids for this class must be manually assigned before ..
PostPosted: Wed Apr 30, 2008 12:03 pm 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi, I'm getting this error-meassage:

Quote:
ids for this class must be manually assigned before calling save()


Cause the public contrutor is forcing the id, I can't see anything wrong.

Here is the code:

Code:
@Entity
public class VitaxDatabaseUser implements Serializable {

    /**
     * Encrypts the given String.
     *
     * @param plainText
     *                the string to be encrypted
     * @return encrypted String
     */
    private static String encrypt(String plainText) {
   .....
    }

    /** The name of the user. */
    @Id
    private String name;

    /** The role of the given user */
    @Enumerated(value = EnumType.STRING)
    private DefinedRoles role;

    /** The password of the user */
    /* Encrypzted kann es evtl. auch länger als 255 Zeichen sein, daher @Lob */
    @Lob
    private String pass;

    /** For Hibernate only */
    @SuppressWarnings("unused")
    private VitaxDatabaseUser() {

    }

    public VitaxDatabaseUser(final String name, final DefinedRoles role, final String pass) {
   this.name = name;
   this.role = role;
   this.pass = encrypt(pass);
    }

    public String getName() {
   return this.name;
    }

    /**
     *
     * @return the encrypted password!
     */
    public String getPass() {
   return this.pass;
    }

    public DefinedRoles getRole() {
   return this.role;
    }

    /**
     * Compares an entered passwort with the stored one.
     *
     * @param plainPass
     * @return
     */
    public boolean passEquals(final String plainPass) {
   return this.pass.equals(encrypt(plainPass));
    }
}



Code:
final VitaxDatabaseUser user = new VitaxDatabaseUser(this.userNameTF.getName(),
         (DefinedRoles) this.levelCB.getSelectedItem(), userPassword);
      final Session s = HibernateUtil.getSession();
      final Transaction tx = s.beginTransaction();
      try {

          s.save(user);
          tx.commit();
      }
....


this.userNameTF.getName() is not null!

What is my mistake?

Thanks a lot in advance.

Greetings Michael


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 01, 2008 4:15 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
it is recommended all Hibernate entities should have a default constructor without arguments; You may add more constructors for your convenience.

I'm not sure this is related to you problem, but you may try.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 01, 2008 11:29 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi Sanne,

I have already an standard constructor for hibernate!

As posted above:
Code:
/** For Hibernate only */
    @SuppressWarnings("unused")
    private VitaxDatabaseUser() {

    }


It is only private to avoid accidental use. Via direct property access hibernate can set the values.

Greetings Michael


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 06, 2008 8:54 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi,

I was a little bit stupid and error blind.
The problem was caused by the mistake that I had invoked getName() instead of getText() on the JTextField. getName() returns null by default, which caused the error.

Greetings Michael


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 7:42 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Sometimes the most obvious errors are the most difficult to find. I feel your pain.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.