I have a Java application that uses Hibernate as the persistence layer. I want to tell Hibernate somehow: if the database version is <50, then ignore this column comment (or set it to Transient). The reason for this is that the database versions of different clients are different, but the entity codes of all sites are the same. For example, I have a class in which the column description2 may be missed in some databases.
< pre>@Entity
@Table(name = “MY_TABLE”)
public class MyTable implements java.io.Serializable {
private Integer serialNo;
private String pickCode ;
private String description1;
private String description2;
@Id
@Column(name = “Serial_No”, nullable = false)
@GenericGenerator (name = “generator”, strategy = “increment”)
@GeneratedValue(generator = “generator”)
public Integer getSerialNo() {
return this.serialNo;
}
@Column(name = “Pick_Code”, length = 25)
public String getPickCode() {
return this.pickCode;
}
< br /> @Column(name = “Description1”)
public String getDescription1() {
return this.description1;
}
@Column(name = “Description2”) // <- this column might miss in some databases
//@TransientIf(…) <- something like this would be nice, or any other solution
public String getDescription2() {
return this.description2;
}
}
Background: I have a large application for different customers The client provides a lot of customization. Now it happens from time to time that a client (more than 500) gets a new function that needs to update the database structure (such as a new field in a table). I released a new version for him, and he runs the database schema Update and use new features. However, whenever any user gets a new feature, all other clients will not perform incremental database updates. They only want to use the latest version, but are affected by the new feature (for that client) , They will never use it.
Instead, I recommend using xml-based mapping and creating different xml mapping files for each client. Since you have about 500 Clients, so you may want to create a group of clients that all share the same mapping file.
At least I think it will be very difficult to maintain different customer needs with one entity model, which will result in a complex code structure. For example If the attributes added for some clients can be null, then you also need to add more null checks to the code. Perform a null check for each client-specific attribute.
Is it possible in some way to tell Hibernate to conditionally ignore missing columns in the database table when performing CRUD operations?
I have a Java application that uses Hibernate as the persistence layer. I want to tell Hibernate somehow: if the database version is <50, then ignore this column comment (or set it to Transient). The reason for this is that the database versions of different clients are different, but the entity codes of all sites are the same. For example, I have a class in which the column description2 may be missed in some databases.
< pre>@Entity
@Table(name = “MY_TABLE”)
public class MyTable implements java.io.Serializable {
private Integer serialNo;
private String pickCode ;
private String description1;
private String description2;
@Id
@Column(name = “Serial_No”, nullable = false)
@GenericGenerator (name = “generator”, strategy = “increment”)
@GeneratedValue(generator = “generator”)
public Integer getSerialNo() {
return this.serialNo;
}
@Column(name = “Pick_Code”, length = 25)
public String getPickCode() {
return this.pickCode;
}
< br /> @Column(name = “Description1”)
public String getDescription1() {
return this.description1;
}
< br /> @Column(name = “Description2”) // <- this column might miss in some databases
//@TransientIf(…) <- something like this would be nice, or any other solution< br /> public String getDescription2() {
return this.description2;
}
}
Background: I have a large application for different clients A lot of customization. Now it happens from time to time that a client (more than 500) gets a new function that needs to update the database structure (such as a new field in a table). I released a new version for him, and he runs a database schema update and New features can be used. However, whenever any user gets a new feature, all other clients will not perform incremental database updates. They only want to use the latest version, but are affected by the new feature (for that client), they It will never be used.
I think it can be replaced only by separating the mapping definition from the entity. Therefore, you cannot use annotation-based mapping.
Instead, I recommend using xml-based mapping and creating a different xml mapping file for each client. Since you have about 500 clients, you may want to create all those that share the same mapping file Client group.
At least I think it will be very difficult to maintain different customer needs with one entity model, which will lead to a complex code structure. For example, if the attributes added for some clients can be null, Then you also need to add more null checks to the code. Perform a null check for each customer-specific attribute.