-->
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: Hibernate und mySQL-Befehl password('password')
PostPosted: Tue Jan 05, 2010 10:26 am 
Newbie

Joined: Tue Jan 05, 2010 10:02 am
Posts: 1
Hallo alle zusammen,

ich versuche mich seit kurzen in Hibernate und stolpere von einen Problem zum Nächsten. Glücklicherweise konnte ich die meisten aber bisher selber lösen. Jetzt suche ich aber bei einem Problem schon ziemlich lange.

Ich habe eine einfache Klasse mit Benutzerdaten und einen Password, mit dem die sich einloggen sollen. Dieses Password möchte ich mit den mySQL-Befehl Passwort('password') wegschreiben. Mit nativen SQL habe ich das auch problemlos hinbekommen. Kann ich den Hibernate anweissen, daß es von sich aus mit dem mySQL-Befehl arbeitet?

Schonmal vielen Dank im Voraus

Gruß
Hasgar

Meine Methode, mit der ich weggeschrieben habe:
Code:
    public void insertUser() {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction transaction = session.beginTransaction();
        String SQLString = "INSERT INTO user (nachname, vorname, loginname, password, anrede_id) ";
        SQLString += "VALUES ('Mustermann', 'Max', 'mMustermann', PASSWORD('password'), 1)";
        Query q = session.createSQLQuery(SQLString);
        q.executeUpdate();
        transaction.commit();
    }


Meine Klasse :
Code:
package pojos;

import java.util.HashSet;
import java.util.Set;

/**
* User generated by hbm2java
*/
public class User implements java.io.Serializable {

    private Integer userId;
    private String nachname;
    private String vorname;
    private String loginname;
    private String password;
    private int anredeId;
    private Set<UserAdresse> userAdresses = new HashSet<UserAdresse>(0);
    private Set<Anrede> anredes = new HashSet<Anrede>(0);

    public User() {
    }

    public User(String nachname, String vorname, String loginname, String password, int anredeId) {
        this.nachname = nachname;
        this.vorname = vorname;
        this.loginname = loginname;
        this.password = password;
        this.anredeId = anredeId;
    }

    public User(String nachname, String vorname, String loginname, String password, int anredeId, Set<UserAdresse> userAdresses, Set<Anrede> anredes) {
        this.nachname = nachname;
        this.vorname = vorname;
        this.loginname = loginname;
        this.password = password;
        this.anredeId = anredeId;
        this.userAdresses = userAdresses;
        this.anredes = anredes;
    }

    public Integer getUserId() {
        return this.userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getNachname() {
        return this.nachname;
    }

    public void setNachname(String nachname) {
        this.nachname = nachname;
    }

    public String getVorname() {
        return this.vorname;
    }

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

    public String getLoginname() {
        return loginname;
    }

    public void setLoginname(String loginname) {
        this.loginname = loginname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getAnredeId() {
        return this.anredeId;
    }

    public void setAnredeId(int anredeId) {
        this.anredeId = anredeId;
    }

    public Set<UserAdresse> getUserAdresses() {
        return this.userAdresses;
    }

    public void setUserAdresses(Set<UserAdresse> userAdresses) {
        this.userAdresses = userAdresses;
    }

    public Set<Anrede> getAnredes() {
        return this.anredes;
    }

    public void setAnredes(Set<Anrede> anredes) {
        this.anredes = anredes;
    }
}


Meine XML-Mapping
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="pojos.User" table="user" catalog="versuch">
        <id name="userId" type="java.lang.Integer">
            <column name="user_id" />
            <generator class="identity" />
        </id>
        <property name="nachname" type="string">
            <column name="nachname" length="50" not-null="true" />
        </property>
        <property name="vorname" type="string">
            <column name="vorname" length="50" not-null="true" />
        </property>
        <property name="loginname" type="string">
            <column name="loginname" length="20" not-null="true" />
        </property>
        <property name="password" type="string">
            <column name="password" length="50" not-null="true" />
        </property>
        <property name="anredeId" type="int">
            <column name="anrede_ID" not-null="true" />
        </property>
        <set name="userAdresses" inverse="true">
            <key>
                <column name="user_id" not-null="true" unique="true" />
            </key>
            <one-to-many class="pojos.UserAdresse" />
        </set>
        <set name="anredes" inverse="true">
            <key>
                <column name="anrede_ID" not-null="true" unique="true" />
            </key>
            <one-to-many class="pojos.Anrede" />
        </set>
    </class>
</hibernate-mapping>



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.