Hi Team!,
I am using hibernate 5.4.2, and I have a below scenario
Expecting your suggestion on how to achieve this using hibernate5 Metadata, MetadataSources, buildMetadata method and SchemaUpdate classes
I have two model jars (for example modelv1.jar and modelv2.jar)
Both these jars contain hbm.xml files and class files for example Product.hbm.xml and Product.class
In modelv2.jar, in Product.hbm.xml i have added a new field say “description” and also in Product.class I have added the same new field and also getter and setter for the new field
How could i use schemaUpdate to generate “alter table” queries for the new fields added ?
Expectation is that, the SchemaUpdate should return me a sql query like:
“alter table product add column description varchar2;”
Could you please share me an example of using SchemaUpdate for this scenario ?
Tried something like below, but I am not sure what “metadata” should be given here
File tempSqlFile = new File("sqlfile");
SchemaUpdate schemaUpdate = new SchemaUpdate();
schemaUpdate.setDelimiter(";");
schemaUpdate.setFormat(true);
schemaUpdate.setOutputFile(tempSqlFile.getAbsolutePath());
schemaUpdate.execute(EnumSet.of(TargetType.SCRIPT), metadata);
Product.hbm.xml file:
Product.java
public class Product
{
private long productId;
private String productName;
private long productPrice;
public long getProductId()
{
return this.productId;
}
public void setProductId(long productId)
{
this.productId = productId;
}
public String getProductName()
{
return this.productName;
}
public void setProductName(String productName)
{
this.productName = productName;
}
public long getProductPrice()
{
return this.productPrice;
}
public void setProductPrice(long productPrice)
{
this.productPrice = productPrice;
}
}
Thank You!
hibhero
hib5 newbie