Rickard Sundin

Greenhorn
+ Follow
since Mar 10, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Rickard Sundin

Another thing to keep in mind is that applying unit tests on an existing project can be very difficult if the code is not well designed. With well designed I here mean that every unit of code (method, class, package) has a well defined responsibility and dependencies between those units are reduced to a minimum.

One of the benifits with Test Driven Development is that it forces you (or at least encourages you) to write well designed code.

/Rickard
[ October 13, 2004: Message edited by: Rickard Johansson ]
20 years ago
I have heard people say that the argument for only testing the public interface of a unit is that you will be able to refactor the internal structure of the unit without having to change the tests. I guess that this comes from bad experience in projects where test discouraged people from doing codechanges since they would also have to rewrite the test (i.e. more work).

I myself find this a bit strange since a solid testbed should give developers the courage to refactor code and be confident they did not break anything.

/Rickard
20 years ago
The authors of the book Hibernate in Action writes:

To use Hibernate effectively, a solid understanding of the relational model and SQL is a prerequisite. You�ll need to use your knowledge of SQL to tune the performance of your Hibernate application. Hibernate will automate many repetitive coding tasks, but your knowledge of persistence technology must extend beyond Hibernate itself if you want take advantage of the full power of modern SQL databases.



If you are interested in the problems and solultions related to Object/Relational Mapping (ORM) using Java, I can recommend the book Patterns of Enterprise Application Architecture which has a nice collection of database patterns.

Best regards
/Rickard Johansson
[ September 16, 2004: Message edited by: Rickard Johansson ]
You can also check out the dom4j framework (http://www.dom4j.org/).

/Rickard

PS.
As a bonus excercise, read the documentation on java.util.Vector and java.util.ArrayList and see if you can

A. Find the basic difference between the two classes, and

B. Decide which of them is the most suitable for you need.
20 years ago
You may also want to look in on the sort methods provided by java.util.Collections (http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html).

/Rickard
20 years ago
Or if you use the xml-style configuration file:
Put the hbm.xml files in a directory 'mappings' (or whatever you like) in the root of your classpath.



/Rickard
Why not make it a configuration property? If not stated, use 'id' as default alias, or state another name (or turn of the alias feature, which is what I would prefer).

When incorporating third party frameworks in systems with estimated long lifespan I try to do everything possible to avoid having to maintain a patched version of any third party framework. This means that I prefer getting invlolved in the development of an open source project (making the change a part of the official release) over maintaining a private patch.

/Rickard
What I have a problem with is that Hibernate puts a restriction (although I admit that it is a rather small restriction) on how the properties of my business objects are named.

When building a new system, knowing from the start that Hibernate is being used, it is not a big deal to avoid using business meaning properties with the name 'id'. But in situations when migrating an existing system to Hibernate, or in when the business objects are modelled before the ORM implementation is chosen, you want to avoid unnecessary changes to the business objects.

/Rickard
If you want to avoid clobbering your source code tree with a lot of hbm.xml-files, and also to avoid maintaining all hibernate configuration in a single file, try putting all mapping files (one per class) in a directory of their own. If you do that you will have to configure your SessionFactory with the names of the mapping files instead of the name of the classes.

/Rickard
I have a Hibernate persisted class 'MyClass' with three properties.


When trying to lookup an instance with a specific 'id' using a HQL query, I run into trouble.


When using a property named 'id' in HQL, it is interpreted as a shortcut for whatever property Hibernate uses for primary key. In the documentation (11.7) I read: "The special property (lowercase) id may be used to reference the unique identifier of an object." In my case this behaviour effectively hides the "real" property 'id'.

How can I rewrite my HQL query so that it uses my property 'id'?

Best regards
/Rickard

PS. A workaround would be to provide my own SQL query, but I would like to solve this problem without leaving HQL.
[ September 01, 2004: Message edited by: Rickard Johansson ]
In my case, Product is not an attribute of Order nor OrderLine, but rather a key that indexes each OrderLine (or set of OrderLines). After Pope mentioning Component Mapping I've been re-reading that secion in Hibernate Reference Documentation. I think perhaps composite-index is what I'm looking for.

Thanx!
/Rickard
[ September 01, 2004: Message edited by: Rickard Johansson ]
I would like to enforce that all access to OrderLine (from Order) is indexed by Product. The system could be restricted to only one OrderLine per Product (0..1) or allow multiple OrderLines per Product (0..*).

Could component mapping help me to accomplish that?

/Rickard