Kiedy automatycznie generuję bazę danych z hibernate.hbm2ddl.auto=create
, tworzone jest "niechciane" ograniczenie unikalności w tabeli odwzorowań. Używam PostgreSQL 9.1, instrukcji CREATE TABLE staje:Kolekcja JPA ma niechciane ograniczenia unikalności w tabeli mapowania
CREATE TABLE schemaname.scanalerts
(
scanid bigint NOT NULL,
alerts_id bigint NOT NULL,
CONSTRAINT fkd65bd7541b5b1a8e FOREIGN KEY (scanid)
REFERENCES rfid.scan (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fkd65bd754860b0886 FOREIGN KEY (alerts_id)
REFERENCES rfid.alert (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT scanalerts_alerts_id_key UNIQUE (alerts_id),
CONSTRAINT scanalerts_scanid_alerts_id_key UNIQUE (scanid , alerts_id)
)
Niepożądane ograniczeniem jest CONSTRAINT scanalerts_alerts_id_key UNIQUE (alerts_id)
, w zasadzie chcę tylko wyjątkową presję na scanid i alerts_id.
używam adnotacje WZP, aby utworzyć mapowanie, tutaj jest mój kod:
@ElementCollection(targetClass = Alert.class, fetch = FetchType.EAGER)
@CollectionTable(name = "scanalerts", schema = RfidConstants.SCHEMA,
joinColumns = @JoinColumn(name = "scanid"),
uniqueConstraints = @UniqueConstraint(columnNames = { "scanid", "alerts_id" }))
private List<Alert> alerts;
Czy istnieje jakiś sposób, aby zatrzymać utworzenie alert_id unikalność?
Dzięki
@JBNizet Oto alert mapowania adnotacje:
@Entity
@Table(name = "alert", schema = "schemaname",
uniqueConstraints = @UniqueConstraint(columnNames = {"message", "alertPriority"}))
public class Alert implements Serializable {
@Id
@Column(name="id")
@SequenceGenerator(name = "alertSeq", sequenceName="ALERT_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "alertSeq")
private Long id;
@Column(name="versionnum")
@Version
private Long version;
@Column(name = "message", nullable = false)
private String message;
@Column(name = "alertpriority", nullable = false)
@Enumerated(EnumType.STRING)
private AlertPriority alertPriority;
Pokaż nam kod i mapowanie alertu. –
@JBNizet Nie mam odwzorowania w klasie Alert w klasie skanowania, czy powinienem tam też mieć? – user2274508
Nie. Pokaż nam kod i mapowania adnotacji. –