I have two problems with the Pojo reverse engeneering:
Sequences and cascades have to be generated.
Primarykeys with Sequences should look like this:
Code:
@Id
@Column(name = "id", unique = true, nullable = false)
@GeneratedValue (strategy = GenerationType.SEQUENCE, generator ="gen")
@SequenceGenerator( name="gen" , sequenceName="public.mytable_id_seq", allocationSize=1)
Cascades should look like this:
Code:
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
I am trying to adopt this by rewriting the reveng strategy:
Code:
import java.util.Properties;
import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.TableIdentifier;
public class ExampleStrategy extends DelegatingReverseEngineeringStrategy {
public ExampleStrategy(ReverseEngineeringStrategy delegate) {
super(delegate);
}
public Properties getTableIdentifierProperties(TableIdentifier arg0) {
Properties pr = new Properties();
pr.put("sequence", "public."+arg0.getName()+"_id_seq");
return pr;
}
public String getTableIdentifierStrategyName(TableIdentifier arg0) {
return "sequence";
}
}
This is not flexible enough to adopt it like I need it. Is there a possibility to go down to string-building level to write what I need? Is there a howto that explaines, how to rewrite the strategy and match ones needs? What are the possibilities?