topcan5
topcan5

Reputation: 1707

JPA Entities from Tables turns int primary key to String

I use Eclipse --> JPA Entities from Tables get generate entities from mysql database. All the tables' primary keys -- ids are int(11) AI PK. So instead of int or long, i am getting String for all the keys. What did i do wrong?

Thanks!

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="LOCATION_ID")
private String locationId; 

Upvotes: 0

Views: 1023

Answers (2)

topcan5
topcan5

Reputation: 1707

Just found out when generating the entity, click on the id and eclipselink will allow you to select the mapping type. Choose int instead of String will do the trick.

Upvotes: 0

Brian Vosburgh
Brian Vosburgh

Reputation: 3276

Eclipse is not correctly parsing your primary key's data type (int(11)). As a result, Eclipse is unable to resolve the appropriate data type to Java type mapping. Because that mapping is missing, Eclipse defaults the datatype for primary key attributes to String. You could remove the display width attribute from your datatype (i.e. the (11)) and Eclipse should be able to more appropriately map the data type.

Upvotes: 2

Related Questions