Permalink
Browse files

become hibernate java class on model A.create

  • Loading branch information...
1 parent 2852ef5 commit e2a1d207a8d34ac477aefe421d71c659b762e25b @mkristian committed Sep 28, 2011
Showing with 15 additions and 1 deletion.
  1. +15 −1 lib/dm-hibernate-adapter/hibernate.rb
@@ -175,6 +175,18 @@ def self.included(model)
model.extend(ClassMethods)
+ # this part is needed for the model A.create method to work
+ model.class_eval <<-EOF
+ alias :initialize_old :initialize
+ def initialize(*args)
+ if self.class.hibernate!
+ self.class.new(*args)
+ else
+ initialize_old(*args)
+ end
+ end
+EOF
+
unless model.mapped?
[:auto_migrate!, :auto_upgrade!, :create, :all, :copy, :first, :first_or_create, :first_or_new, :get, :last, :load].each do |method|
model.before_class_method(method, :hibernate!)
@@ -218,6 +230,7 @@ def to_java_class_name
end
def hibernate!
+ result = false
relationships.each do |property, relationship|
next unless relationship
@@ -250,12 +263,13 @@ def hibernate!
add_class_annotation annotation
Hibernate.add_model become_java!(false), name
+ result = true
@@logger.debug "become_java! #{java_class}"
else
@@logger.debug "become_java! fired already #{java_class}"
end
-
+ result
end
def mapped?

0 comments on commit e2a1d20

Please sign in to comment.