0
votes

i was wondering about that if i can change or set values of table structure that hibernate does when i map object to Mysql.

my question is if i have this entity class:

@Entity
@Table(name="user_table")
public class User {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;

@Column(name="name")
@Basic(optional=false)
private String name;


private String adress;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

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

public String getAdress() {
    return adress;
}

public void setAdress(String adress) {
    this.adress = adress;
}

}

hibernate by default create table with this but my point is that the (name) column is create with [ VARCHAR(255) ], colud i change it for example to [ VARCHAR(50) ]

note:

i try to use something like => @Type(type="varchar(50)")

OR

@Type(type="varchar-50")

but it did not work !!!

any help?

1

1 Answers

0
votes

Setting lenght shoud do the trick

@Column(name="name", length = 50)
@Basic(optional=false)
private String name;

By default lenght 255.