Skip to content

Commit

Permalink
Merge pull request #24 from LeovR/uniqueColumn
Browse files Browse the repository at this point in the history
Extended UniqueConstraintSnapshotGenerator to include @column(unique = true) annotations (Fixes #14)
  • Loading branch information
nvoxland committed Nov 14, 2013
2 parents f236835 + af8ec08 commit 40e3360
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro
LOG.info("Found unique constraint " + uniqueConstraint.toString());
table.getUniqueConstraints().add(uniqueConstraint);
}
Iterator columnIterator = hibernateTable.getColumnIterator();
while (columnIterator.hasNext()) {
org.hibernate.mapping.Column column = (org.hibernate.mapping.Column) columnIterator.next();
if(column.isUnique()) {
UniqueConstraint uniqueConstraint = new UniqueConstraint();
uniqueConstraint.setTable(table);
String name = "UC_" + table.getName().toUpperCase() + column.getName().toUpperCase() + "_COL";
uniqueConstraint.addColumn(0, column.getName());
uniqueConstraint.setName(name);
LOG.info("Found unique constraint " + uniqueConstraint.toString());
table.getUniqueConstraints().add(uniqueConstraint);
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/example/ejb3/auction/Item.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.ejb3.auction;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
Expand All @@ -13,6 +14,7 @@ public class Item {
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator="ITEM_SEQ")
@SequenceGenerator(name="ITEM_SEQ",sequenceName="ITEM_SEQ")
private long id;
@Column(unique = true)
private String name;

public long getId() {
Expand Down

0 comments on commit 40e3360

Please sign in to comment.