Reputation: 113
I'm using Hibernate to create entities class from MS SQL. But with NVARCHAR Hibernate changes to Serializable type. It makes some errors, exeptions because conflict between NVARCHAR and Serializable when I CRUD!
Have anyway to change Serializable to String when Hibernate auto creates entities class?
Sorry, my Eng skills aren't good so I can't find information of this problem in this site.
I'm using JBoss tool for LUNA Eclipse and I do following steps:
This is a class after create by Hibernate
@Entity
@Table(name = "SubMenu1", catalog = "MySite")
public class SubMenu1 implements java.io.Serializable {
private byte id;
private Menu menu;
private Serializable name;
public SubMenu1() {
}
public SubMenu1(byte id, Menu menu) {
this.id = id;
this.menu = menu;
}
public SubMenu1(byte id, Menu menu, Serializable name) {
this.id = id;
this.menu = menu;
this.name = name;
}
@Id
@Column(name = "id", unique = true, nullable = false)
@GeneratedValue(strategy=GenerationType.AUTO)
public byte getId() {
return this.id;
}
public void setId(byte id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idMenuParent", nullable = false)
public Menu getMenu() {
return this.menu;
}
public void setMenu(Menu menu) {
this.menu = menu;
}
@Column(name = "name")
public Serializable getName() {
return this.name;
}
public void setName(Serializable name) {
this.name = name;
}
I want Serializable changes to String that do automaticly, i don't need change by my hands
Upvotes: 4
Views: 2234
Reputation: 2807
Edit your hibernate.reveng.xml
file & add the following entry in the <type-mapping>
section of the file:-
<sql-type jdbc-type="NVARCHAR" hibernate-type="string"/>
When the Hibernate Generation Wizard will generate the classes for you then it uses hibernate.reveng.xml
for type conversion. So when the generator encounter NVARCHAR
datatype it check for it's equivalent hibernate data type
& convert it into String
type.
Upvotes: 6