Hi,
here is the code. (some getter setters left out). Application is working well. I am using a hardcoded annotation configuration.
AnnotationConfiguration configuration = new AnnotationConfiguration() .setProperty("hibernate.connection.driver_class", "org.firebirdsql.jdbc.FBDriver") .setProperty("hibernate.connection.url", "jdbc:firebirdsql:localhost/3050:D:/Atlas/Database/Atlas.fdb") .setProperty("hibernate.dialect", "org.hibernate.dialect.FirebirdDialect").setProperty("hibernate.connection.username", "RIDDBA") .setProperty("hibernate.connection.password", "Vegas1499").setProperty("hibernate.connection.pool_size", "10") .setProperty("show_sql", "true") .setProperty("hibernate.current_session_context_class", "org.hibernate.context.ThreadLocalSessionContext"); // .setProperty("hibernate.query.substitutions", "true J, false N"); werkt // niet
configuration.addAnnotatedClass(Activiteit.class); configuration.addAnnotatedClass(BO.class); configuration.addAnnotatedClass(AtlasVersion.class); configuration.addAnnotatedClass(Client.class); configuration.addAnnotatedClass(DBC.class); configuration.addAnnotatedClass(DBCActiviteit.class); sessionFactory = configuration.buildSessionFactory();
package nl.rid.domein.bo;
import java.util.ArrayList; import java.util.List;
import javax.persistence.Column; import javax.persistence.MappedSuperclass; import javax.persistence.Transient; import javax.persistence.Version;
import nl.rid.common.message.MessageList;
@MappedSuperclass public abstract class BO { public static String SYSTEM_ID = "systemId";
// common fields protected Integer systemId; private Integer versionLock;
// private List<BusinessRule> beforeInsertRules = new ArrayList<BusinessRule>(); private List<BusinessRule> beforeUpdateRules = new ArrayList<BusinessRule>(); private List<BusinessRule> beforeDeleteRules = new ArrayList<BusinessRule>();
public BO() { addRules(); }
public static String[] getFieldNames() { return new String[] { "systemId" }; }
protected abstract void addRules();
@Version @Column(name = "VERSION_LOCK") public Integer getVersionLock() { return this.versionLock; }
public void setVersionLock(Integer aValue) { this.versionLock = aValue; }
@Transient public boolean isNew() { return (this.systemId == null); }
public void validateBeforeInsert(MessageList aMessageList) { for (BusinessRule br : beforeInsertRules) { br.execute(this, aMessageList); } }
public void validateBeforeUpdate(MessageList aMessageList) { for (BusinessRule br : beforeUpdateRules) { br.execute(this, aMessageList); } }
public void validateBeforeDelete(MessageList aMessageList) { for (BusinessRule br : beforeDeleteRules) { br.execute(this, aMessageList); } }
protected void addRuleBeforeInsert(BusinessRule aRule) { beforeInsertRules.add(aRule); }
protected void addRuleBeforeUpdate(BusinessRule aRule) { beforeUpdateRules.add(aRule); }
@Transient public String getDefaultDisplayValue() { if (this.systemId == null) { return ""; } else { return this.systemId.toString(); } }
public void executeOnLoad(Object[] state, String[] propertyNames) {} }
@Entity @javax.persistence.SequenceGenerator(name = "GeneratorDBC", sequenceName = "GENERATOR_DBC", allocationSize = 1) public class DBC extends BO {
private DBCStatus dbcStatus; private DBCStatus dbcDBStatus; private Client client; private Date startDatum; private Date eindDatum; private Integer aantalDagen; private Date sluitingsDatum; private Medewerker medewerker; private Integer minutenGerealiseerd; private ZorgverzekeraarLabel zorgverzekeraarLabel; private BigDecimal totaalBedrag; private BigDecimal contractBedrag; private boolean isBetaald; private Date betaalDatum; private BigDecimal betaaldBedrag; private String vecozoId; private Integer vecozoStatus;
private Set<DBCActiviteit> dbcActiviteiten = new HashSet<DBCActiviteit>();
public DBC() { this.dbcStatus = DBCStatus.CONCEPT; }
public void setDbcStatus(DBCStatus aDbcStatus) { this.dbcStatus = aDbcStatus; }
@Column(name = "DBC_STATUS") @Enumerated(EnumType.STRING) public DBCStatus getDbcStatus() { return dbcStatus; }
@PostLoad public void doAfterLoad() { this.dbcDBStatus = this.dbcStatus; System.out.println("doPostload dbcStatus = " + this.dbcStatus); }
@Transient public DBCStatus getDbcDBStatus() { return this.dbcDBStatus; }
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "GeneratorDBC") public Integer getSystemId() { return this.systemId; }
public void setSystemId(Integer aSystemId) { this.systemId = aSystemId; }
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }) @JoinColumn(name = "FK_CLIENT") public Client getClient() { return this.client; }
public void setClient(Client aClient) { this.client = aClient; }
@Column(name = "AANTAL_DAGEN") public Integer getAantalDagen() { return this.aantalDagen; }
public void setAantalDagen(Integer aAantalDagen) { this.aantalDagen = aAantalDagen; }
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }) @JoinColumn(name = "FK_MEDEWERKER") public Medewerker getMedewerker() { return this.medewerker; }
public void setMedewerker(Medewerker aMedewerker) { this.medewerker = aMedewerker; }
@Column(name = "MINUTEN_GEREALISEERD") public Integer getMinutenGerealiseerd() { return this.minutenGerealiseerd; }
public void setMinutenGerealiseerd(Integer aAantal) { this.minutenGerealiseerd = aAantal; }
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }) @JoinColumn(name = "FK_ZORGVERZEKERAAR_LABEL") public ZorgverzekeraarLabel getZorgverzekeraarLabel() { return this.zorgverzekeraarLabel; }
public void setZorgverzekeraarLabel(ZorgverzekeraarLabel aZorgverzekeraarLabel) { this.zorgverzekeraarLabel = aZorgverzekeraarLabel; }
@OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "FK_DBC") public Set<DBCActiviteit> getDBCActiviteiten() { return this.dbcActiviteiten; }
public void setDBCActiviteiten(Set<DBCActiviteit> aDBCActiviteiten) { this.dbcActiviteiten = aDBCActiviteiten; }
private void calculateAantalDagen() { this.aantalDagen = 0; if ((this.startDatum != null) && (this.eindDatum != null)) { Calendar start = Calendar.getInstance(); Calendar eind = Calendar.getInstance(); start.setTime(this.startDatum); eind.setTime(this.eindDatum); long div = (eind.getTime().getTime() - start.getTime().getTime()); long minuten = div / (1000 * 60 * 60 * 24); this.aantalDagen = new Integer(new Long(minuten).intValue()); } }
@Override protected void addRules() { BusinessRule validateDBCFieldsNotEmpty = new ValidateDBCFieldsNotEmpty(); // before insert addRuleBeforeInsert(new ValidateDBCUniqueForClient()); addRuleBeforeInsert(validateDBCFieldsNotEmpty); addRuleBeforeInsert(new ValidateDBCInitialState()); // before update addRuleBeforeUpdate(validateDBCFieldsNotEmpty); addRuleBeforeUpdate(new ValidateDBCStateChange()); } }
|