Hi,
Why is Hibernate replacing existing tables in the database with its own, different tables upon a call to session.find("from X")?
Here's my mapping document:
Code:
<class name="User" table="tdb_user">
<id name="id" type="string" column="id">
<generator class="uuid.hex"/>
</id>
<property name="username" column="username" type="string"/>
<property name="realname" column="realname" type="string"/>
</class>
Here's the class I'm mapping:
Code:
public class User {
private String id;
private String username;
private String realname;
public User() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getRealname() {
return realname;
}
public void setRealname(String name) {
this.realname = name;
}
}
And this is what I used for creating the table before triggering the SELECT from within Tomcat:
Code:
create table tdb_user (
id VARCHAR(32) PRIMARY KEY,
username VARCHAR(32) NOT NULL UNIQUE,
password VARCHAR(32) DEFAULT NULL,
realname VARCHAR(100) NOT NULL
) TYPE=InnoDB;
Note that I've included a 'password' column in the database and that isn't mapped to the User class.
Finally, this is what happens when Hibernate has had a chance to do the SELECT:
Code:
mysql> describe tdb_user;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id | varchar(32) | | PRI | | |
| username | varchar(32) | | UNI | | |
| password | varchar(32) | YES | | NULL | |
| realname | varchar(100) | | | | |
+----------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql>
mysql> describe tdb_user;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id | varchar(255) | | PRI | | |
| username | varchar(255) | YES | | NULL | |
| realname | varchar(255) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql>
I'd really appreciate any pointers towards where I'm going to the woods.
I'm using Hibernate 2.1.6 and MySQL 4.0.22.
-Lasse-