2

My Entity class has a column which looks like this:

@Entity
@Table(name = "addons")
public class AddonsEntity {
    private int id;
    private String name;
    private BigDecimal price;
    private int addonGroupId;
    private int order;
    private AddonGroupsEntity addonGroupsByAddonGroupId;

    @Id
    @Column(name = "id", nullable = false, insertable = true, updatable = true)
    @GeneratedValue(generator="increment") @GenericGenerator(name="increment", strategy="increment")
    public int getId() {
        return id;
    }

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

This convert to sql like:

create table addons (id integer not null, ....);

As there is nothing like integer in mysql,its throwing an error.

version:

'org.hibernate', name: 'hibernate-core', version: '4.3.10.Final'
'org.hibernate', name: 'hibernate-c3p0', version: '4.3.10.Final'
'mysql', name: 'mysql-connector-java', version: '5.1.35'
 Mysql Server version: 5.6.25 Homebrew
 Java 1.8

SQL Translation:

create table addons (
        id integer not null,
        addon_group_id integer not null,
        name varchar(200) not null,
        order integer not null,
        price decimal(2,0) not null,
        addonGroupsByAddonGroupId_id integer not null,
        primary key (id)
    )

ERROR:

2015-07-21 01:26:13 [] ERROR [Scanner-1] o.h.t.h.SchemaExport [SchemaExport.java:426] HHH000389: Unsuccessful: create table addons (id integer not null, addon_group_id integer not null, name varchar(200) not null, order integer not null, price decimal(2,0) not null, addonGroupsByAddonGroupId_id integer not null, primary key (id)) 
2015-07-21 01:26:13 [] ERROR [Scanner-1] o.h.t.h.SchemaExport [SchemaExport.java:427] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order integer not null,price decimal(2,0) not null,addonGroups' at line 5 
Amogh
  • 4,453
  • 11
  • 45
  • 106

2 Answers2

2

Problem is not with integer. problem is in create statement. As you see in create statement order column is created with order integer not null,... where as ORDER is a reserved word in Mysql.

If you are using annotations, solution is

@Column(name = "[ORDER]", nullable = false)
    public int getOrder() {
        return this.order;
    }

Or

@Column(name = '"ORDER"', nullable = false)
    public int getOrder() {
        return this.order;
    }

If you are using hbm file, solution is:

   <property name="order">
            <column name="[ORDER]" not-null="true" />
   </property>

Or

<property name="order">
    <column name='"ORDER"' length="255" not-null="true" />
</property>
Amogh
  • 4,453
  • 11
  • 45
  • 106
0

It seems to me that your application is not correctly configured to use the MySQLDialect. How to properly configure Hibernate depends on the environment you are executing it in, so please have a look at the proper documentation.

A starting point for this might be the Stack Overflow Question "Why do I need to configure the SQL dialect of a data source?"

Community
  • 1
  • 1
Martin C.
  • 12,140
  • 7
  • 40
  • 52