Implementation classes and temporary state

Hello,

I understand implementation classes are your solution to implement business logic and to avoid overwriting the body of methods when a source code has to be regenerated.

Am I right that using business logic would be something like this:
(MyClass as MyClassImpl).CalculatePrice()? Implementation classes are not instantiated I think.

If so, then what about the following: imagine that my business logic operations should keep temporary state of calculation. This means I need some variables in MyClass that should not be persistable. How can I achieve it?

Cheers,
Tadeusz

Hello Tadeusz,

You do not need to cast. The retrieve methods will return the implementation class. About generating non-persistable attribute, this is possible. Just set persistable = No for the attribute. But notice that the instance will lost when the session is closed.

Best regards,
Jick
non-persistable-attribute.png

Thanks, works really great!

The next question concerns a totally different subject: transactions. What strategy are you using for concurrency control? Is there any way of setting optimistic/pessimistic concurrency control?

Tadeusz

Hellp Tadeusz,

You are welcome. Pessimistic can be supported by hibernate locking API, and we do not support optimistic at the moment.

Best regards,
Jick

Hi Jick,

We have a complex hierarchy of classes with “Table per subclass” inheritance strategy. However, Hibernate xml generated for a subclasses contains a “lazy” attribute in a “property” element. This results in run-time exception:
the “lazy” attribute is not declared.
This probably means that Hibernate does not implement lazy retrieve on a column level.

We implemented some preprocessing to correct generated sources, but this will give us extra work when the projects grows (app. 150 persistable classes). Is there any fix for this problem?

Cheers,
Tadeusz

Hello Tadeusz,

We tested and do not find any problem. We also checked the XML schema and make sure that it support lazy. Are you using your own Hibernate library? Could you provide us with the full log for tracing the problem?

Best regards,
Jick

Hello,

I will.

I have another question:
I would like to put some attributes in implementation classes that have no importance for business (like time stamps and counters to arrange audit trail in Data Tier with triggers; another example: time stamps for optimistic concurrency control). All this should be completely transparent to higher tiers, so I overwrite Save and Delete methods in implementation classes. I want to have this attributes also persistable. I try the following:

  1. Create an implementation class.
  2. Make it persistable with inheritance startegy “Table per class hierarchy”

However, when I synchronize to ERD, there is a separate table created for the implementation class and it has no connection to a table for a model class.

Am I doing anything wrong?
Or, is it not possible to model such a concept?
Or, VP lacks this functionality?

Cheers,
Tadeusz

Hello Tadeusz,

It seems that what you wanted is to have persistable attributes in the subclass. Then why you use the implementation class, which is not expected to be persistable? Could you clarify on this issue? Thank you.

Best regards,
Jick

Hi Jick,

Ok, if implementation classes is not expected to be persistable, then my idea will not work, and I will have to get functionality I need in a different way.

Another question:
I want to have a protected attribute in a base class. But, whatever I do I always get public setter and getter in a base class. I do not want it! Am I doing anything wrong or is it a bug?

Cheers,
Tadeusz

Hello Tadeusz,

You may set this from the Advance Settings before generating code. Please see the attached image for detail.

Best regards,
Jick

getter_setter_attr.png

Thanks!

Works good for field members.

But it seems that it does not work for associations. I do specify association visibility as private, and yet a property generated for an association role is generated as public.

Cheers,
Tadeusz

Hello Tadeusz,

I regret that the current design supports only relationships that are defined as attributes. For relationships that are defined as association, we will support it later on.

Best regards,
Jick

Jick,

I create two classes with a unidirectional association (Master and Child classes; assoctiation multiplicity 1 and 0…*). They map correctly to ERD entities with a foreign key MasterId from Child to Master. The key is not nullable (as it should be). However, this results in the following error when I save a Master object:
“Cannot insert the value NULL into column ‘MasterID’, table ‘test1.dbo.Child’; column does not allow nulls. INSERT fails”

What shoul I do with it?

Cheers,
Tadeusz

Hello Tadeusz,

How did you perform saving? You should call master.save()

Best regards,
Jick

Hi Jick,

Of course!

        Master master = MasterFactory.CreateMaster();
        master.A = "abc";

        Child child = ChildFactory.CreateChild();
        child.B = "xyz";
        master.children.Add( child);

        master.Save();

Cheers,
Tadeusz

Hello Tadeusz,

Sorry but we cannot reproduce your problem. Are you using Java or .NET ORM? Have you set nullable to false in ERD? You must set it to false to generate the correct mapping.

I would be grateful if you can send us your project or code to take a closer look at this problem.

Best regards,
Jick

Hi Jick,

Attached you will find a test project. I am using .NET 2, Visual Studio 2005 and SQL Server 2003 or 2005.

Why do I have to set nullable to false? This is a DDL generated by VP:

create table Master (ID int identity not null, A varchar(255) null, primary key (ID));
create table Child (ID int identity not null, B varchar(255) null, MasterID int not null, primary key (ID));
alter table Child add constraint FKChild766137 foreign key (MasterID) references Master;

As you can see “MasterID int not null” which is correct.

Cheers,
Tadeusz
Test1.zip

Jick,

Another problem of master-detail association. When I delete a master object (m.Delete()) then only [i] a master object is deleted from the database and child objects remain there as orpants!

I would expect that invoking Delete() for a master cascades to delete for all children!

Cheers,
Tadeusz

Jick,

Concerning the previous message, I got this working. I have to use composition instead of plain association - makes sense :wink:

Cheers,
Tadeusz

But nullable is still a problem.

[quote=Tadeusz Gruzlewski]Jick,

Another problem of master-detail association. When I delete a master object (m.Delete()) then only [i] a master object is deleted from the database and child objects remain there as orpants!

I would expect that invoking Delete() for a master cascades to delete for all children!

Cheers,
Tadeusz[/quote]

Hello Tadeusz,

I regret that your need is not supported for the .NET ORM. Below is a segment extracted from Hibernate’s site:

Very Important Note: If the column of a association is declared NOT NULL, NHibernate may cause constraint violations when it creates or updates the association. To prevent this problem, you must use a bidirectional association with the many valued end (the set or bag) marked as inverse=“true”. See the discussion of bidirectional associations later in this chapter.

Ref: http://www.hibernate.org/hib_docs/nhibernate/html/collections.html

Sorry about this.

Best regards,
Jick