How to create a unique constraint in an entity class using jpa project eclipse

I plan to integrate ORM into my project, so I used the Eclipse JPA project to create feature classes from old databases. A total of 168 entity classes where it is generated and this is normal. But in some restrictions, such as nullable, uniquethey are not automatically generated.

For example, I need something like this: -

@Column(name="USER_NAME",unique = true)
private String userName;

but after auto-generating entities, there is no unique restriction in the code. How can I achieve this simply?

Any suggestions would be helpful.

+4
source share
4 answers

JPA , , . JPA , .
, .

Find the latest JPA on a new screen

+2

@Unique , . PersistenceException ( ), ( , ). :

@Unique
@Column(name="USER_NAME")
private String userName;
+1

. , DDL. , javax.persistence.schema-generation.database.action drop-and-create.

+1
source

You need to use Jboss's Hibernate Tools, which will allow you to do better reverse engineering.

http://hibernate.org/tools/

There are many tutorials outside of which explain how to use sleep mode tools.

+1
source

Source: https://habr.com/ru/post/1686173/


All Articles