- This topic has 6 replies, 4 voices, and was last updated 15 years, 2 months ago by
Brian Fernandes.
-
AuthorPosts
-
Scott DunbarParticipantI’m reverse engineering a PostgreSQL 8.3 database. I have many tables that get their primary key from a PostgreSQL sequence. I’m unable to see the sequences in the reverse engineered data and, for the columns that this applies to I must manually fix this every time I reverse engineer.
The code generated looks like:
@Id @Column(name = "company_id", unique = true, nullable = false) public Integer getCompanyId() { return this.companyId; }
However, after manually fixing this it should look like:
@Id @Column(name = "company_id", unique = true, nullable = false) @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "company_id_seq") @SequenceGenerator(name="company_id_seq", sequenceName="company_id_seq") public Integer getCompanyId() { return this.companyId; }
I’d like the reverse engineering to know that this is generated via a sequence. It is impossible to get the UI to put the sequenceName into the SequenceGenerator annotation – that has to be done manually.
I have complete control over the DB at this point – is there a better way to do this? I’d like to not have to muck with auto-generated code every time the schema changes. Any thoughts?
This is a Java 6 environment, JPA is backed by Hibernate, MyEclipse is 7.0, build 7.0-20081201. Thanks for any help.
Loyal WaterMemberI have asked the dev team to look into this and they will get back to you with a reply asap.
Brian FernandesModeratorI’m afraid the current RE tools will not detect sequences to generate the code you need. The only solution I can suggest is to modify the velocity templates with conditional code to generate a sequence where you need it, but this can be cumbersome if you have to deal with many sequences.
A note on how templates can be used (for both JPA and Hibernate) is here:
http://www.myeclipseide.com/documentation/quickstarts/hibernate/#5-5I’ll add sequence detection to our feature list for the RE tools.
stefanmaderMemberHi,
where can I find the Velocity Templates for JPA and Hibernate in MyEclipse 7.x?(I want to remove the schema and catalogue names from the generated files, as my program will use databases in different schemas. I suppose the only workaround is to change the velocity templates?)
Brian FernandesModeratorStefan,
Yes, changing the templates would be the way to go. Please see this tutorial for instructions on finding & changing the templates: http://www.myeclipseide.com/documentation/quickstarts/hibernate/#5-5
stefanmaderMemberHi,
this seems to be the link for MyEclipse 6.5, but I’m currently using 7.0.
Did the templates change between these versions?Also, we are considering a migration to 7.5, will I have to make adjustments to the templates after migration?
best regards
Stefan
Brian FernandesModeratorStefan,
I’m sorry about that – the online documentation should have been updated to reflect the most recent version, I’ll talk to the documentation team about getting that fixed.
The templates changed in version 7.1. So if you are using 7.0, the 6.5 version of the templates are correct. If you move to 7.5, you will need the 7.1 version of the templates – you can find this in the same tutorial embedded in your MyEclipse install (see Help > MyEclipse Learning Center > JPA / Hibernate / Spring Development > Hibernate Tutorial)
I believe you would need to change only two templates, ConcretePojo.vm and Ejb3TypeDeclaration.vm (for the schema / catalog attributes in .java files). They should be easy to move to the new version of the templates if you choose to move to 7.5 later.
Hope this helps.
-
AuthorPosts