Menu

Basic Newbie Questions

Help
2008-03-14
2013-04-25
  • Matt Stucky

    Matt Stucky - 2008-03-14

    Sorry if this is answered somewhere, i looked around and didn't see anything.

    So sql2java looks like the following: given a database it will build the POJOs/beans from the table schema, along with listeners and managers and some other stuff.  That all looks great.

    If you want to add functionality, is the normal way to do it to extend the created bean?  I'd like to add fields to my tables and rebuild via sql2java.  All correct so far?

    next question.  given an app, say a forum, that has users, threads and messages.... the threads-to-messages mapping is one to many.  does sql2java handle that automatically or do i need to do it at a higher level?  also, it appears that when a pojo changes, in my app code i'll need to call save to write back to the database (which is fine).

    lastly, in the example above, the users-to-threads is many-to-many, is there an example of how sql2java would handle this?  the internal cross-reference table that manages the relationship would not need to be a pojo/bean. 

    thanks in advance!!

     
    • Gerits Daan

      Gerits Daan - 2008-03-15

      Hi Matt,

      Let's start with your first question. It's always possible to make changes to your database model and regenerate your sources. The downside is that any changes made to these sources before regeneration will be lost. We are working on it and the next version will allow you to keep your changes between regeneration.

      For the last two questions I have to look at the code, because I don't know how this is handled inside 2.6. Again in 3.0, the upcoming release, support for relationships are available. Many-to-many is a bit of a tricky one, but if I remember right I saw some code about relationship handling in the 2.6 release too. I would suggest to just try it out. Maybe Alain Fagot (kameleono) can answer this in more detail.

       
    • Matt Stucky

      Matt Stucky - 2008-03-15

      Thanks for the answer!

      as to regenerating sources, i understand losing changes and actually would prefer it that way.  if i want to change anything i'll just extend the generated class - in fact i'd prefer it that way!  part of the problem i've had w Hibernate is it tries too hard to do too much and becomes a black hole.

      maybe i need to rephrase my question:  it appears either "best" or "have to" handle one-to-many and many-to-many relationships in my code.  is that correct?  i guess from a "control freak" point of view, i can tolerate my ORM handling one-to-many because it's simple, but the many to many can get ugly so i'd actually prefer to handle this at the app level.  just want to know if there is a simple, clean, understandable sql2java way of handling these that i haven't seen.  but if not, i'll do the bean work myself

      come to think of it I didn't see any JDBC-database-connection code either.  i assume that's also handled at the app level?  (mysql database in my case)

      thanks

       
      • Gerits Daan

        Gerits Daan - 2008-03-15

        Well, I think we mix-up things a bit. SQL2Java will generate you a framework and will generate code which is able to convert a relational model into an Object oriented one. Once the framework is generated, you can package it into a jar file and use it inside your application. Sql2Java won't be used at runtime since it's the generated framework taking care of the actual 'neat' part.

        As for your relationship question. To play save I would suggest to handle it in your own code. As said before, the upcoming release will handle more of this but since I'm not a 2.6 developer I can't give you a straigt answer on this one.

        I don't know for sure, but isn't there a database handler class anyware?

        Again sorry I can't help you more on this issue. I'm involved in the next release and can't actually remember how it's done in the old code. Kameleono would be able to help you a lot more.

         
        • Alain Fagot Béarez

          Hi guys !

          There is a whole part of the 2.6 version I never used nor maintained.  As Daan said he is not a 2.6 developper, I would say I am only the 2.6 maintainer...

          About relationships... both the one-to-many and the many-to-many should be handled by the generated code.  If anything went wrong with the code you get generated for your model, please report a bug and I will try to fix it:
          http://sourceforge.net/tracker/?group_id=54687&atid=474467
          (there is only one still active that I can't fix due to the internal architecture)

          As far as I understood the generated code, the relationships are implemented as lazy ones.  That means you will have to handle the coherence of creates, updates and deletes.

          As for the "database handler", the preferred way is passing a configured DataSource to the generated Manager, through Manager.getInstance().setDataSource(yourOwnDS) and there still is the old way by passing the path to a .properties file to the manager.getInstance().configure("your/path/to/your/database.properties") with the following keys in it:

          jdbc.driver=the driver class
          jdbc.url=the database access url
          jdbc.username=the user that will read and write to the database
          jdbc.password=the corresponding password

          Hope you will find this helpful.

          Alain

           
    • Matt Stucky

      Matt Stucky - 2008-03-19

      ok, understand that....

      so how would I get from that Manager class to the CustomerManager (from your example) so i can
      access the CustomerManager.countAll() method?  the CustomerManager doesn't have a configure method.

      thanks

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.