Results 1 to 19 of 19

Thread: object-relational mapping support?

  1. #1
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default object-relational mapping support?

    Hello,

    Does Qt provide support for object-relational mapping?

    I know there is some support with QSqlTableModel such as: select, insert, update, and delete. But, I don't see support for object relationships such as: association, inheritance, polymorphism, composition, and collections.

    Any help greatly appreciated.

    Thanks,
    Ben

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: object-relational mapping support?

    You mean with databases? Qt only handles relational databases.

  3. #3
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: object-relational mapping support?

    I'm looking for something to glue the model in code to the model in the database ... not just unrelated attributes ... but the attributes of a class object, it's parent object, objects it contains, etc.

    This is called object-realational mapping in database world. It's a programming technique that links databases to object-oriented language concepts.
    http://en.wikipedia.org/wiki/Object-relational_mapping

    As an example, there's a service in Java called Hibernate that performs this for you.
    http://www.hibernate.org/

    Anyways, I'm hoping to leverage Qt to support as much of this as is possible.

    Thanks,
    Ben

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: object-relational mapping support?

    If you need an object oriented database, why don't you use an object database management system instead of using a relational database? There are differences between object databases and relational databases, you can't simply "translate" one into another without loosing its functionality. As for the object model - you have the QAbstractItemModel interface which probably has everything you need - parent-child relationships and "properties" (called "roles" in Qt context). You can make a custom model from your database if you wish. QSqlTableModel is of course an implementation of that design, but it's flat - no parent-child relation. If you want one, you have all means to implement it.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: object-relational mapping support?

    Quote Originally Posted by wysota View Post
    If you need an object oriented database, why don't you use an object database management system instead of using a relational database? There are differences between object databases and relational databases, you can't simply "translate" one into another without loosing its functionality.
    He doesn't want to use object oriented database. What he wants is automatically generated classes that will allow him to conveniently access the relational database.

    I've never seen anything like this for Qt (note that it doesn't mean it doesn't exist), but I think it should be fairly easy to write a little Perl script that would generate QSqlTableModel subclasses with some accessors methods and enum for column identification.

    Quote Originally Posted by wysota View Post
    If you want one, you have all means to implement it.
    The idea of object-relational mapping is to avoid writing code by hand.

  6. #6
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: object-relational mapping support?

    Quote Originally Posted by jacek
    What he wants [...] classes that will allow him to conveniently access the relational database..
    Exactly.

    Quote Originally Posted by jacek
    The idea of object-relational mapping is to avoid writing code by hand.
    Indeed. It's quite difficult and time consuming.

    From my reading there are two alternatives ... runtime reflection or code generation. I don't have a preference for either approach. Although, my experience lends itself more towards runtime intospection (which Qt provides some capability there already).

  7. #7
    Join Date
    Oct 2006
    Posts
    42
    Thanks
    1
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: object-relational mapping support?

    Quote Originally Posted by brcain View Post
    Does Qt provide support for object-relational mapping?
    Qt doesn't have a persistance framework such as Java's Hibernate if that was what you were thinking of, but it does have a module that provides capabilities for seamless database integration to your Qt applications.

    Check out the detailed description of the Qt Sql Module.

  8. #8
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: object-relational mapping support?

    Quote Originally Posted by mm78 View Post
    Qt doesn't have a persistance framework such as Java's Hibernate if that was what you were thinking of
    That's what I need ... even if I have to write my own.

    The thing that seems missing with QtSQL is how to map the object assocations. I can see how it handles stand-alone attributes. But, I don't think there's any inherent support for object relationships such as aggregation, inheritance, etc.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: object-relational mapping support?

    Quote Originally Posted by brcain View Post
    From my reading there are two alternatives ... runtime reflection or code generation. I don't have a preference for either approach. Although, my experience lends itself more towards runtime intospection (which Qt provides some capability there already).
    You could try to exploit Qt's property system, but you will loose type safety this way, as you will have to pass data as QVariants.

  10. #10
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: object-relational mapping support?

    Quote Originally Posted by jacek
    You could try to exploit Qt's property system.
    Yes ... that's my intended approach. And I think that will suffice on the code side.

    However, I'm still left with how to map the object relationships

    If I'm terribly concerned about type-safety, then I guess I'm stuck with code generation ... perhaps using template metaprogramming (which I have very limited experience with).

  11. #11
    Join Date
    Oct 2006
    Posts
    42
    Thanks
    1
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: object-relational mapping support?

    Quote Originally Posted by brcain View Post
    That's what I need ... even if I have to write my own.
    Feel free to write it - you're probably not the only one who want such a framework


    Quote Originally Posted by brcain View Post
    The thing that seems missing with QtSQL is how to map the object assocations. I can see how it handles stand-alone attributes. But, I don't think there's any inherent support for object relationships such as aggregation, inheritance, etc.
    Correct. You'll be able to connect to databases, run queries and fetch the results quite effortlessly, but Qt won't do magic and handle associations or map the fetched data to objects. It still beats using native drivers though, both in flexibility and complexibility. Anyhow, the native drivers doesn't support associations or OR-mapping either.

    I think such an OR-mapping framework would be outside the scope of Qt anyway. To me it sounds more like a framework on top of Qt, just like Hibernate is a framework on top of Java and JDBC.

    Do you have any suggestions for how such a framework would work? From the users point of view.

  12. #12
    Join Date
    Oct 2006
    Posts
    42
    Thanks
    1
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: object-relational mapping support?

    BTW this is a good article on OR-mapping:
    Mapping Objects to Relational Databases: O/R Mapping In Detail

  13. The following user says thank you to mm78 for this useful post:

    brcain (26th October 2006)

  14. #13
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: object-relational mapping support?

    Quote Originally Posted by mm78 View Post
    Feel free to write it - you're probably not the only one who want such a framework
    Easier said than done.

    Quote Originally Posted by mm78 View Post
    Do you have any suggestions for how such a framework would work? From the users point of view.
    I wish I had more experience in this area. First I guess I'd look at the Data Access Object (DAO) design pattern. Also, hopefully I can find enough documentation to get a glimpse at how Hibernate is designed.

    Any suggestions are worth gold at this point.

  15. #14
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: object-relational mapping support?

    Quote Originally Posted by mm78 View Post
    BTW this is a good article on OR-mapping:
    Mapping Objects to Relational Databases: O/R Mapping In Detail
    Much thanks ... looks like a great article ... reading now.

    Do you know of any C++ toolkits ... that I might integrate with Qt? There appear to be numerous options for Java.

  16. #15
    Join Date
    Oct 2006
    Posts
    42
    Thanks
    1
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: object-relational mapping support?

    Quote Originally Posted by brcain View Post
    I wish I had more experience in this area. First I guess I'd look at the Data Access Object (DAO) design pattern. Also, hopefully I can find enough documentation to get a glimpse at how Hibernate is designed.
    Any suggestions are worth gold at this point.

    Do you know of any C++ toolkits ... that I might integrate with Qt? There appear to be numerous options for Java.
    What do you need this OR-Mapping framework for? I've worked on several applications where we simply handcoded the OR-Mapping because that was the most efficient thing to do at the time. A framework would be better and more flexible of course, but would it really be worth the effort?

    Hibernate and other persistence frameworks would be a good starting point to see how this could be implemented, but I think the most important thing at this moment would be to figure out if you really need it and what your requirements are if you really do need it.

    Sadly I don't know about any C++ persistance frameworks that would integrate with Qt. Maybe that is what I should build my future "billion dollar business plan" up on?

  17. #16
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: object-relational mapping support?

    Quote Originally Posted by mm78 View Post
    What do you need this OR-Mapping framework for? I've worked on several applications where we simply handcoded the OR-Mapping because that was the most efficient thing to do at the time. A framework would be better and more flexible of course, but would it really be worth the effort?
    That's a loaded question. I'll try to give you a quick summary. I'm devloping a tool to analyze the performance of highly distributed engineering/constructive dynamical simulation systems. It will also provide a "live" simulation exercise monitoring capability. The initial simulation system being used to prototype the tool is a military weapon system.

    Besides the obvious analytical components (e.g. object/attribute browser, plots, graphs, query wizard), the tool will also provide a 3D visualization component -- allowing systems to be viewed more naturally.

    The tool will provide an open database schema and plugin architecture to support user extensibility of new models and view types.

    The most difficult part ... the tool makes as little assumptions as possible about the specific domain of the data being modeled. It will use the database schema to inspect the types of objects being modeled ... their attributes and object associations. As much as possible, I'm trying to keep the domain as open as possible ... not assuming any particular types of dynamic platforms, sensors, constraints, etc.

    Here's a little more detail ... hope it's coherent ... it has been a long day

    Automate analysis and visualization of large, complex, distributed computing simulation systems – while leveraging capital of legacy systems potentially constructed using disparate programming languages and mixed levels of fidelity.

    Implement an architecture that leverages existing/open component technologies where possible while enabling organizations to extend/contribute capability back to user-community through an open and extensible plug-in interface mechanism. Component technologies would consist of data collection, relational database querying, and COTS/GOTS charting, 2D/3D maps, plotting, imaging, and analysis software.

    n-tier ... distibuted simulations to send messages to a data collector for buffering/translating/writing data to a database. A trigger mechanism would notify tool when an update occurs. This simplifies adapting the tool to various languages/interfaces and allows it to easily support both live and playback modes.

    Multiple, distributed tools could be active, querying data from the same or dissimilar scenarios at various points in time.

    Within the tool, multiple graphics windows for side-by-side comparison of data from multiple view types to inspect time-dependent behavior.

  18. #17
    Join Date
    Oct 2006
    Posts
    42
    Thanks
    1
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: object-relational mapping support?

    Quote Originally Posted by brcain View Post
    It will use the database schema to inspect the types of objects being modeled ... their attributes and object associations. As much as possible, I'm trying to keep the domain as open as possible ... not assuming any particular types of dynamic platforms, sensors, constraints, etc.
    I guess this would be a two component tool. First a code generator that runs at compile time to generate classes for your value objects and sql, and second a run time component that create and populate your objects.

    If you want to do everything at runtime I guess you'd be better of by using Ruby than C++.

    My database knowledge might be a bit dusty, but I'm not sure how inherentance is expressed in the schema. If it is at all. Isn't it just a purely logical concept in the logical data model?

    Anyway, Qt won't give you this. It will give you a nice interface to doing platform independent database access, but not this high-level framework. Not even Hibernate would give you what you need (I think).

  19. #18
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: object-relational mapping support?

    Quote Originally Posted by mm78 View Post
    If you want to do everything at runtime I guess you'd be better of by using Ruby than C++.
    Only problem is I need C++ for graphical plugins (e.g. OpenSceneGraph, OGRE, OpenGL, shaders). I've heard there is now a Java binding for some; but, that's a bit of a jump from where I am now.

    Quote Originally Posted by mm78 View Post
    My database knowledge might be a bit dusty, but I'm not sure how inherentance is expressed ... Isn't it just a purely logical concept in the logical data model?
    Likely. Again, my experience leaves a bit to be desired here. BTW, thanks for ideas.

    Quote Originally Posted by mm78 View Post
    Anyway, Qt won't give you this. Not even Hibernate would give you what you need (I think).
    From Hibernate's description, it purports to handle the logical mapping for several types of class assocations such as inheritance and composition.

    If I don't find such a framework, I may have to handle this incrementally ... first writing my own mapping functions.

  20. #19
    Join Date
    May 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: object-relational mapping support?

    We developed an open source library named QHibernate.

    QHibernate is a Hibernate ORM(Object Relation Mapping) port for C++ and Qt Framework.
    Current version is a proof of concept work.
    It is used with PostgreSQL 9.4 and Qt 5.4.1.

    Features:
    • Qt5
    • PostgreSQL
    • Class mapping xml
    • Class mapping xml
    • Hibernate configuration xml
    • one-to-many, one-to-one, many-to-one mappings



    You can find some details, source and download links here:
    http://www.cstech.com.tr/en/QHibernate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.