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 
5
  • Please post the error that you are getting? Commented Jul 20, 2015 at 19:02
  • ..and which data type you expect at DB side? Commented Jul 20, 2015 at 19:07
  • @Amogh: Updated with error Commented Jul 20, 2015 at 20:04
  • Actually problem is with column name order, ORDER is an reserved word in MySQL so that create statement is getting failed. If you are using annotation then try adding adding/modifying annotation @Column(name="[order]") in AddonsEntity class. Commented Jul 20, 2015 at 20:17
  • Along with my answer if you don't want to go changing property by property you can set <property name="hibernate.globally_quoted_identifiers">true</property> in hibernate config. Commented Jul 20, 2015 at 20:40

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Along with this if you don't want to go changing property by property you can set <property name="hibernate.globally_quoted_identifiers" value="true"/>.
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?"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.