Update to code for <<ORM Persistable>> classes

I’m evaluating SDE for VisualStudio and trying C# code generating capabilities.
“Update to code” function doesn’t work for classes with <> stereotype. Is it your bug or design decision?
I use VisualStudio 2003.

Hi Jacenty,

We provide a set of options for you to customize the generated ORM code, so it will handle differently.

To produce code for ORM persistable class, please select Modeling > ORM > Generate Code… from the main menu.

Best regards,
Jick

Hi,

I used this stereotype, because I’d like to generate ER diagram from my class model, but I don’t plan to use OR mapper (usually we use a different one, but I think it’s good to have possibility of have different architectural choices). Maybe it’s possible to generate ERD without stereotyping classes as <>?

Another issues is, that I’d like to have real round-trip between model and code. ORM code generator will probably overwrite my changes?

Regards,
Jacek

Hi Jacenty,

Thanks for your reply.

If you have used the OR mapper to produced code, why you need the round-trip feature to produce code? You will then have 2 set of code. One produced by the OR mapper, one produced by round-trip. I am sorry, but I do not quite understand your need. Would you mind clarifying a little bit?
(because we haven’t see this kind of need before. I hope you could explain a little bit)

Best regards,
Jick

Hi,

From my point of view, class models purpose is not only carrying data, but implementing business logic too.

E.g.:

public class Invoice
{
   private LineItemCollection lineItems;

  ...

[b]  public double CalculateTotal()
  {
     double total = 0.0;
     foreach(LineItem item in lineItems)
        total += item.Value;
     return total;
  }[/b]

}

If I implement this method in generated code I will be not able to regenerate code according to development of my model. I’m forced to write something like “service class” to implement processing logic.

Of course, this case is rather thrivial, but I’m sure you can imagine much more sophisticated. I like implementing business logic in business objects instead of building complex service classes. It’s more object-oriented.

Hi Jacenty,

We can understand your need. In fact, we have a function to fulfill your need. It is called the “ORM Implementation Class”. Let me tell you how to use this first, and then let you know what is the effect of using the implementation class.

To create an ORM implementation class:

  1. Move to cursor the model class. This shows a set of icons around the model.
  2. Press on the ‘Create ORM implementation class’ icon, hold the mouse button, and drag downwards. This generate an ORM implementation class for you.
  3. Add the business logic in the implementation class

I captured an image to show you the flow.

Then what’s the effect of using implementation class? You also aware that the model class code were overwritten every time you generate ORM. The implementation will never been overwritten. You can add the business logic there.

Hope you find it useful!

Have a nice weekend!

Best regards,
Jick

Thank you. I think, that this solution is quite good.

Have a nice weekend too,

Jacek

Hi Jacenty,

More information about the implementation class:

If you have not make changes to the generated implementation class (code), this class will be overwritten everytime (since you haven’t make any changes). Once you have made a change to the file and saved, it will no longer be overwritten.

Best regards,
Jick

Thank you,

I have a little bit more complicated situation. We currently use different ORM, than You. I afraid, that probably it’s not possible to integrate it with your solution.
Of course, we can use VP without OR mapping, but synchronization between class model and ER model is useful.
From my point of view, possibility of mapping classes to tables without ORM would be useful.

Hi Jacenty,

You can stereotype the classes as ORM Persistable without generating code. For the code, you can keep on using the code produced by your ORM tool. This will let you have both the code (from your own ORM tool) and the ability to synchronize between object model and data model (from VP). Am I correct?

Best regards,
Jick

Not exactly.
My ORM tool doesn’t generate any code. It only reads and writes objects to a database using xml-based mapping files (like Hibernate).
So, I would like to either generate ERD for classes without <> stereotype, or generate code for <> classes from SDE. Another way would be more flexible code generator for <> classes.

Regards,
Jacek

Hi Jacenty,

Thank you for your reply. Could you let me know why you do not use our ORM features? I ask because if you use our ERD with your ORM tool, they may be incompatible with each other. What kind of flexibility do you need? If your suggestion is meaningful, we can make it as options.

Best regards,
Jick

  1. My persistent classes must inherit from special PersistentObject class or implement IpersistentObject interface.
  2. Collection classes must be or inherit one of special collection type class ( PersstentList , PersistentSet , PersistentCollectionBase ) or implement one special interface ( ILazyLoad ).
  3. I use different set of classes to specify queries, so your typed queries will not work.
  4. My persistent classes should not have an attribute representing primary key. Identity is handled by persistence infrastructure.
  5. We use one more inheritance mapping strategy, called Roll down . Attributes of superclasses are represented as columns of tables of subclesses (see http://forums.visual-paradigm.com/posts/list/1765.html ).

Hi Jacenty,

I think you can do in this way:

To remove the ORM Persistable stereotype for all classes on the diagram:
Remove the ORM Persistable model in Model Tree (see diagram A)

To reassign the ORM Persistable stereotype for all classes on the diagram:

  1. Set one of the class to be ORM Persistable
  2. Select all the class
  3. Set all of them to be ORM Persistable via the popup menu (see diagram B)

When you want to have code synchronization, remove the stereotype. When you want to sync to ERD, reassign the stereotype.

Hope this helps.

Best regards,
Jick

Hi,
I can generate my persistable classes with Instant Generator, and then use similar to <> technique to work with additional code.
I tried to use this tool and it works fine, but it would be nice to have some documentation about code templates (*.VM files).

Regards,
Jacek