如何防止域类的重复插入?
Locations location = Locations.findByLocationXY(locationxy)
if (location == null)
{
LocationManagement lm = new LocationManagement()
location = lm.getSingaporeLocation(locationxy)
location.save(flush:true)
}
class Locations {
int id
String locationName
String locationXY
static constraints = {
id(blank:false, unique:true)
locationName (blank:false)
locationXY (blank:false, unique:true)
}
def afterInsert = {
id= this.id
locationName = this.locationName
locationXY = this.locationXY
}