This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Consider: create table Persons (PERSON_ID integer primary key, PersonName varchar(100)) create table Users (USER_ID integer primary key, UserName varchar(100)) create table PersonUsers (PERSON_ID integer, USER_ID integer, constraint pkPU primary key (PERSON_ID, USER_ID) Now generate Entity Class from Database. You will see: @JoinTable(name = "PersonUsers") @ManyToMany private java.util.Collection <br.srv.brinfo.beans.User> coUsuario; where it should be: @JoinTable(name = "PersonUsers", joinColumn=@JoinColumn(name="PERSON_ID", referencedColumnName="PERSON_ID"), inverseJoinColumn=@JoinColumn(name="USER_ID", referencedColumnName="USER_ID")) @ManyToMany private java.util.Collection <br.srv.brinfo.beans.User> coUsuario; (sorry if there is some syntax mistake, I typed everything here instead copy/paste). Since NetBeans 5.5 knows reference table and reference columns, correct (and complete) mapping should be generated. Error messages are not clear enough ("parameter PersonId_PERSON_ID does not exists") to direct user to correcting the problem. Tested agains GlassFish b43 and b48 (latest dev build), NB 5.5 Daily 200605050500 and 200605090500. All presents same problem. Developer could not proceed without figuring out why queries can't executed (and error message dont help either).
This is filed as a duplicate. This is not a P1 issue do I will close this report and keep the other one. Will fix for 5.5. Thanks. *** This issue has been marked as a duplicate of 76202 ***
The problem here is not the fact NetBeans is not generating a third class (as stated in 76202, but the fact that correct column names are not being put by the wizard. It not only doesn't work, but prevents developer to continue working. The error message is not enought clear for developer (without deep knoledge of POJO persistence) to solve and get project working. If it's not P1, at least it's P2 and is not definitelly duplicate of 76202.
I think it is a duplicate. Please read the entire description of 76202 catefully again. This is the priority guideline: http://qa.netbeans.org/bugzilla/bug_priority_guidelines.html IMO it is P3.
Hi! Again, the problem reported here is not lack of relation. In fact, when I've created my beans, relation was created, but only with table name for join table. My relation table has no additional columns than relation columns. The problem is because field names follow my own naming pattern, and wizard is expected to respect this names. And about priority guidelines, it's a P2: "Product feature doesn't work, a workaround may exist but it's difficult to use or impractical" "Product feature doesn't work": Out of the box, the ManyToMany relation doesn't work for existing tables. "A workaround may exists, but it's difficult to use or impratical": since error message thrown by Application Server during runtime reports a invalid "column name" that could not even can be found (throught Find... in project), is really very difficult to fix it. The reported column name could not be find in any XML file, neither in Java code. So, or developer goes deep inside defaults assumed for particular AS implementation (in this case, it's Glassfish, but it could be other), or the wizard don't goes into defaults for this kind of mapping (so explicit mapping of relation columns should be obligatory). Difference from 76202 is because I have no additional columns in relation table, neither mapping was missed. The mapping is present, but it's wrong. If you wish to add this issue to 76202, well, this is your choice, but add clearly that problem is lack of "@JoinColumn" for joinColumns and inverseJoinColumns Example of code generated by wizard (so the relation was generated, in contrary to what is reported in 76202): @JoinTable(name = "RL_USUARIO_PESSOA") @ManyToMany private java.util.Collection <sgeejb.beans.TbUsuario> coUsuario; Expected code from wizard: @JoinTable(name = "RL_USUARIO_PESSOA", inverseJoinColumns=@JoinColumn(name="CO_USUARIO", referencedColumnName="CO_USUARIO"), joinColumns=@JoinColumn(name="CO_PESSOA", referencedColumnName="CO_PESSOA")) @ManyToMany private java.util.Collection <br.srv.brinfo.beans.TbUsuario> coUsuario; I think this make things clear! If you wish, transfer this information to 76202, but raise 76202 to P2 and copy this info into them. Without fixing it, ManyToMany with existing tables doesn't work out-of-the-box, neither is easy to fix (specially if developer isn't expert in persistence - target for Wizards).
Is the DB script above complete? Looks like it creates 3 tables but I do not see where is the definition of foreign keys. I just want to make sure that I can reproduce.
There are similar issues, like issue 74117 or issue 76202 which are tracked as P3. It was a consensus of the team working on this for issue 74177 to track this as a P3. We will fix it for 5.5, do not worry. I will look at whether it is a duplicate or not when I can test with the complete SQL script.
Created attachment 30356 [details] Sample database diagram
Created attachment 30357 [details] Script for sample database diagram
Created attachment 30358 [details] Sample project (with correct code)
Created attachment 30359 [details] Video showing problem and solution
Richter is right, it is not a duplicate of issue 76202. Reopening.
Changing to [55cat] to be conformant with NetCAT program.
Checking in src/org/netbeans/modules/j2ee/persistence/entitygenerator/CMPMappingModel.java; /cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/Attic/CMPMappingModel.java,v <-- CMPMappingModel.java new revision: 1.1.2.1.2.1; previous revision: 1.1.2.1 done Checking in src/org/netbeans/modules/j2ee/persistence/entitygenerator/DbSchemaEjbGenerator.java; /cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/Attic/DbSchemaEjbGenerator.java,v <-- DbSchemaEjbGenerator. java new revision: 1.1.2.1.2.6; previous revision: 1.1.2.1.2.5 done Checking in src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/JavaPersistenceGenerator.java; /cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/JavaPersistenceGenerator.java,v <-- JavaPersistenceGene rator.java new revision: 1.1.2.2.2.26; previous revision: 1.1.2.2.2.25 done
Something still not right. I checked out from cvs, and made a local build. I tired with the simple example of three tables, A, B, and MAP_A_B, and it gave a tomcat exception when trying to associate one entity with the other. I will attach the database schema and the exception below. After creating the entities from the database, and the jsf from entities, access the pages, create a new A, create a new B, and then go to the list of As, access the details of the A instance and try to add a new B to it. This will give a tomcat exception as the one show in the attachement below.
Created attachment 30777 [details] DERBY db schema
Created attachment 30778 [details] tomcat exception
This is a different problem again, but let's keep it here since this is our favorite bug number :-) In the ManyToMany case the controller does not have helper methods for new/destroy of related objects from a detail page of entity. This works ok only for the 1:n relationship. I will look at that (as time permits).
There is an additional issue. Where exists a composed primary key, the @JoinColumn references must (obligatory) name="", referencedColumnName="" (look at specs, or Right Clic -> Verify Project). Actual implementation just put "@JoinColumn(name="...")", and should be @JoinColumn(name="...", referencedColumnName="...").
"brviking", please do not pile any more issues in this report. I will fix the last issue reported by Halim, for any other problems please file a separate issue. Also, for that other issue: I do not understand what exactly you mean. AFAICT it generates both name and referencedColumnName in JoinColumn annotation. Is that not true?
/cvs/web/jsf/src/org/netbeans/modules/web/jsf/palette/items/Attic/JsfForm.java,v new revision: 1.1.2.4.2.18; previous revision: 1.1.2.4.2.17 /cvs/web/jsf/src/org/netbeans/modules/web/jsf/wizards/Attic/JSFClinetGenerator.java,v new revision: 1.1.2.24; previous revision: 1.1.2.23 hopefully I fixed the controller for many to many
Sorry. I didn't want to be boring anyone... Just reporting the previous solution was incomplete. About the my many to many last report the answer is yes, there is missing referencedColumnNamnes, but I didn't tested in later daily builds. I was very busy here. I'll test again in latest daily build. Tkx.
Pavel: I just updated form CVS and made a local build to test this new fix. I am a little confused now. I was expecting it to work in a different way that how it works now. Let's say we have a Student and Course tables related in a many-to-many relation. Now if i create 10 students, and then I create 10 courses. Now I go to the list of courses, click on the ID of a course to open its details. Now there is no way to associate any of the students that I created earlier with this course. The only option I have is to create new students that will be associated with this course. The way it works now has really no practical use. The way I thought it should work is that once you open the detail of a Course, you will have the opportunity to add any number of the existing students to that course. I think this would be the natural way that a usere would want to use an application that has a many-to-many association. Please let me know if you agree. I am reopening this report for now. If you don't agree with me, you can change it to the appropriate status. thanks.
Richter: I did not mean it bad, I just think this issue is getting a little bit confusing and a bit long. Please test it and report a new defect it you find that it does not work. Halim: What you are desribing makes sense and would be a good thing to add. I would like to minimize the amount of new code though and focus only on fixing existing issues. The problem is that I would need to figure out what exactly it should look like in the first place..... Do you mean that creating new Students from a detail of Course makes no sense? Maybe I should keep the "New Student" link and just add some minimal UI to add an existing Student. One way to do it would be to have a combo box with Student and an Add button with Students, so you can at least add one at a time. For adding multiple I would probably need to create a whole new page for selection of Students which sounds like too much work at this stage. Let me know if you have any ideas. Thanks.
Pavel: You are absolutely right. Adding multiple Students to a Course in one shot would require a whole new page. If this is not an option at this time (which I perfectly understand), your suggestion of having a combo box that allows adding one student at a time would be GREAT! As for the link that you have now for adding a new student, i don't see this necessary, but it probably won't hurt. So if you want to keep it, it is your call. One thing that would be nice though is that after you create this new student, it will bring you back to the *course* page and not back to the students list. This will probably require changes in the "new student" page becase it will have two destinations now depending on where it was called from. Anyway... If you want to choose only one thing to do, I would vote for the combo to allow adding an existing student to a course. Thanks for your great effort.
Actually, after a little more thinking, I take back what I said about the "New Student" being unnecessary. I can see where it can come in handy in some situations. So I agree with what you said about that. So it would be great if you can keep it and just add the combo to enable the addition of a single existing "Student".
I filed 79243 for the support to add items into many to many. First because that one is not a P2, IMO, and second because the original problem (and a few more) was resolved.
v