Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Polymorphism? #12

Open
chasm opened this issue Aug 31, 2010 · 7 comments
Open

Polymorphism? #12

chasm opened this issue Aug 31, 2010 · 7 comments
Labels

Comments

@chasm
Copy link

chasm commented Aug 31, 2010

I've been playing around with the Circumflex ORM and it's very nice, but I don't see anything to permit any type of inheritance -- single table or otherwise. Is there a provision for this? I use a lot of traits, often for the purposes of inclusion polymorphism. Not possible? Possible? Planned? Forget it?

Thanks!

@inca
Copy link
Owner

inca commented Aug 31, 2010

Planned :)

At the beginning, we've summarized all our experience with STI and Table-Per-Subclass mapping techniques in Hibernate and decided that none of these schemes work more-or-less stable and robust. So we decided that implicit polymorphism described in their documentation is the best solution.

As far as I can tell, nothing stops you from mixing in some trait and then query separate tables several times and collect results into one collection. Your application, thought, might require something more than that. We'll ellaborate on this in 2.0.

Thanks for pointing us into this issue!

@chasm
Copy link
Author

chasm commented Aug 31, 2010

My cup runneth over! Implicit would be very cool. I would have been happy enough with nothing more than inclusion. Unfortunately, I need this right now, so I'll have to figure something out. I'll either roll my own (per your suggestion) or maybe I'll try using Squeryl with Circumflex. That might be fun, and I've become reasonably proficient with Squeryl lately.

Do you have a timeline for 2.0?

@inca
Copy link
Owner

inca commented Aug 31, 2010

Yepp. It's at least a couple of months, because we have lots to do: from complete reorganization of web framework to adding query statistics, dialects support and testing to ORM. Sorry for inconvenience.

In a meantime, it would be great if you'll share your experience in Squeryl-Circumflex integration.

Thanks!

@chasm
Copy link
Author

chasm commented Sep 1, 2010

Sadly, turns out that Squeryl doesn't do inheritance either, so I might as well stick to Circumflex. Any suggestions re how to do a quick roll-your-own single-table inheritance system that will get me by until your brilliant solution can be unveiled to a waiting world? My current plan is to include an automatically set "type" column (don't worry, I won't call it "type"), persist the objects by superclass, and do the casts before saving/after retrieving. What do you think?

Re using Squeryl with Circumflex: nothing to it. Comment out the Circumflex ORM, add the Maven dependency to Squeryl and cglib, and follow the directions on the Squeryl site. Gotta love Circumflex!

<!-- Squeryl -->
<dependency>
  <groupId>org.squeryl</groupId>
  <artifactId>squeryl_2.8.0</artifactId>
  <version>0.9.4beta8</version>
</dependency>

<!-- Needed for Squeryl -->
<dependency>
  <groupId>cglib</groupId>
  <artifactId>cglib-nodep</artifactId>
  <version>2.2</version>
  <scope>compile</scope>
</dependency>

http://squeryl.org/getting-started.html

@inca
Copy link
Owner

inca commented Sep 3, 2010

I do not foresee any problems with that. However, I can give you a couple of limitation of using the STI patterns:

  • you can't enforce NOT NULL constraints on the subclass fields;
  • your table may become very wide;
  • it is not as extensible as table-per-XXX approaches, because if you add new implementations, you'll have to modify your table.

Nevertheless, it would be fine if your solution will work for you.

Best regards,
Boris Okunskiy

@chasm
Copy link
Author

chasm commented Sep 3, 2010

True, but these are all the normal problems with STI. But I'm too lazy so for the moment I'm simplifying things and working around it. Have to get something to show the client very soon. I'll back fit it later.

Any way to do one-to-one relations? And I presume that many-to-many is done using a "bridge" object and two one-to-many relationships? Or did I miss something?

Thanks for all the help. I'm liking Cx a lot and looking forward to 2.0.

Chas.

@jdeboer3000
Copy link

Hi guys,

I am trying to migrate from java+hibernate to scala+circumflex. I was using inheritance strategy in hibernate which worked well. And what about now in circumflex ? It seems you planned to implement something. You talked about "nothing stops you from mixing in some trait and then query separate tables several times and collect results into one collection". How do you do that ? I am not so familiar with scala yet. Could you provide me with an example ? Thanks for your help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants