pattern « Development « JPA Q&A





1. Pattern suggestions needed (Hibernate + Guice)    stackoverflow.com

I'm looking for suggestions on how to inject runtime dependencies into JPA entities retrieved from Hibernate. My problem is essentially this: I have a number of different subclasses of a Transaction object. ...

2. Design pattern for translatable Hibernate models    stackoverflow.com

I have a Hibernate model that (simplified) looks like this:

public class CoverageLine {
  private Long id;
  private String coverageText;
  private boolean coveragePresetTo = true;
  private OnNewPolicy onNewPolicy ...

3. Understanding hibernate internals    stackoverflow.com

Im trying to understand how hibernate works under the hood, how it manages lazy load, transactions, data mappers, unit of work, identity maps, etc. I wrote a small object model, and im ...

4. Hibernate and Flyweight    stackoverflow.com

Is there a way to use Flyweight objects with the hibernating persistence mapping? My data model contains many objects that will be the same. Instead of having a separate instance for ...

5. Design question    stackoverflow.com

We are building software in java, and are new to it. I confused about JPA. Normally in MVC pattern, SQL queries are hidden in model. And controller can't access the db directly. When ...

6. What is the basic pattern for using (N)Hibernate?    stackoverflow.com

I'm creating a simple Windows Forms application with NHibernate and I'm a bit confused about how I'm supposed to use it. To quote the manual:

ISession (NHibernate.ISession) ...

7. How to implement the state design pattern in a JPA domain model    stackoverflow.com

I want to implement the state design pattern in JPA. The way I am currently doing this is outlined in this blog post. The author uses an enum containing all ...

8. JPA ORM Design Patterns    stackoverflow.com

I need new design patterns in JPA/ORM instead of POJO/JDBC/DAO patterns. Is there any recommended link? RGDS

9. design pattern in hibernate?    stackoverflow.com

can anyone tell me what design patterns in hibernate? thanks in advance.





10. How make a Maven package using JPA, but independent of service provider; and later how to plug in my service provider by user of this package?    stackoverflow.com

I'm not sure if it's even possible... I have some design patterns, which I want in my special Maven package (#1) - all these patterns use javax.persistence. I don't want this package ...

11. Can I use the builder design pattern together with hibernate?    stackoverflow.com

Assuming I have this class:

public class MyEntity {
  private int id;
  private String name;
  private MyEntity(int id, String name) {this.id= id; this.name = name;}
  public static class ...

12. Hibernate design pattern question    stackoverflow.com

Im working with Hibernate. It works great. However, say that I have a class that corresponds to a database table with only getters and setters and toString, equal methods. Now I ...

13. JPA: what is the proper pattern for iterating over large result sets?    stackoverflow.com

Let's say I have a table with millions of rows. Using JPA, what's the proper way to iterate over a query against that table, such that I don't have all an ...

14. Hibernate code..some confusion    stackoverflow.com

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction transaction = null;
    try {
        transaction = session.beginTransaction();
  ...

15. JPA/Hibernate: Sub-typing vs. strategy 'pattern'    stackoverflow.com

The following is a JPA annotated type hierarchy, in which all data fields (and associated getters and setters) are members of the supertype along with abstract methods for implementing business logic. ...

16. Hibernate Design Pattern    coderanch.com

DTO is an antipattern designed because you could not transfer Entity Beans to the client. A Hibernate Mapped Object could be considered a DTO, since it can be transferred to a client. Also in EJB3, Hibernate 3 is an implementation of Entity Beans, which can now be transferred to the client. DAO is just having classes that do the Data Accessing ...





17. JPA and Decorator pattern    coderanch.com

I'm trying to implement the decorator pattern to solve a design problem and don't know how best to work it with Toplink... I have a number of JAXB-generated Java code that I'm using to get started. That means that there's a bunch of imported javax.xml.datatype.XMLGregorianCalendars lying around that aren't Serializable and are otherwise cantankerous since they extend (just) Object. My problem ...

18. Hibernate and related patterns    coderanch.com

19. Hibernate patterns    coderanch.com

20. Hibernate and Design Patterns    coderanch.com

I have often used the DAO design pattern, excellent for managing more simple relationships with Hiberante. The DTO design pattern adds an extra layer to the application but really separates the the object model from the data layer. I know that this is what hibernate is supposed to do but I have often found it useful to have another layer of ...

21. Patterns & JPA in Hibernate Recipes    coderanch.com

22. Hibernate design pattern problem    coderanch.com

I am quite new in Hibernate. I managed to learn myself a bit about Hibernate but the biggest problem I have is a designing problem. I use Hibernate with Spring, which is responsible for transactions and JSF, which I use in presentation layer. I use entities which represent database records and DAOs which implements database operations (one public DAO's method == ...

23. One-to-many for different types : is there a design pattern?    forum.hibernate.org

I have 3 types of Forms : - CustomerForm.java - SupplierForm.java - ProductForm.java These are all persisted towards the database Now all these forms have a property List attachments Attachment : - name - url - description How do I need to map this is Hibernate since I want to map 3 tables towards 1 table of attachment. The table containing ...

24. Hibernate design pattern problem    forum.hibernate.org

I am quite new in Hibernate. I managed to learn myself a bit about Hibernate but the biggest problem I have is a designing problem. I use Hibernate with Spring, which is responsible for transactions and JSF, which I use in presentation layer. I use entities which represent database records and DAOs which implement database operations (one public DAO's method == ...

25. Where does Hibernate use the Facade Pattern?    forum.hibernate.org

Hi dear users, I have a very general question (arisen in a very passionate discussion with my colleague). Would appreciate it if someone could give me some detailed info or web links. Generally viewed, is there a point where Hibernate use the Facade Pattern? And if so, how is implemented? Who are the participants? Info? Links? Thank you so much! greets ...

26. Issue with interface - Design Pattern Strategy    forum.hibernate.org

Hi experts, Im trying to use Hibernate 3.5.3 to persist my Classes of my project. All concrete classes have related tables into my database (they are entities), they were mapped using Annotations and Hibernate recognizes them. But my problem is into main class GeneralUser: @Entity @Table(name = "F_AEXA_MEMBERS") publicclass GeneralUser implements Serializable { /** * */ privatestaticfinallongserialVersionUID = 4234518752392079435L; @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY) @JoinColumn(name="F_AEXA_MEMBERS_CPF") ...

28. Example which seperates Model from VC in MVC pattern?    forum.hibernate.org

Hello, Today i have looked at a couple of examples which uses hibernate and are based arround the MVC pattern. I looked at "appfuse" (also called "struts-hibernate"), "struts-resume" and "xpetstore". In all these examples the Controller part of MVC is aware that Hibernate is used in the Model. My o'reilly struts book says that should be avoided in most cases, the ...

29. NullObject pattern    forum.hibernate.org

I have some null objects and I would like Hibernate to return these when it cannot find any results from a given query. For example say I have this code public User getUser(Long id) { return (User) session.load(UserImpl.class, id); } if this user with ID=1 does not exist, I would like it to return me the null object I specified somewhere ...

30. Hibernate Pattern    forum.hibernate.org

I'm using Struts and the Thread Local Session pattern... In the begin of the request I open a Transaction, and after in the DAO classes I retrieve the session, but I never flush or close the session in the DAO... Then, in the end of request I commit or rollback the Transaction and close the Session. Is This the right way ...

31. one-to-one: Hibernate implementation of some design patterns    forum.hibernate.org

Hi: I have three tables in a DB: User, Employee, and Consultant. Each Employee or Consultant is a User. The table User contains basic data pertinent to both Employees and Consultants (such as the name, e-mail address, username, etc.). The tables Employee and Consulant contain other relevant data elements. When an employee or a consultant logs in, the login is checked ...

32. Why Threadlocal pattern?    forum.hibernate.org

I am starting to question about my Threadlocal design. Here is the question. In terms of ThreadLocal pattern recommened on the website, it never clears to me when you should close the session. Most likely you are not? Since you don't know what that thread will do, right? But all the reading telling me that I should 'close' the session ASAP ...

33. Hibernate J2EE Integration Pattern    forum.hibernate.org

Hello, Daniel D'Alessandro and myself have written a short white paper on how we have sucessfully integrated Hibernate into a large scale, production J2EE application. The paper outlines the goals behind the pattern, the methodology used and provides a downloadable implementation of the system. A trivial application using the system wil be posted in the next few days utilising the code ...

34. Is there a design pattern for this...?    forum.hibernate.org

Hi there ! Imagine that in your application you want to manage documents. For this you have in your database a DOCUMENTS table. This table has a column named DOC_TYPE. As the name says, this colomn gives the type of the document (for exemple txt, doc, xls, ppt , htm...). On the java side you have a Document class mapped to ...

35. pattern-forum    forum.hibernate.org

hi, what do think about a hbm-pattern-collection plattform where we could discuss mapping strategies and shape a set of best-practice patterns to common problems. like opensource sais: why invent the wheel twice. i.e. UserManagement is a pretty common task in all kind of applications. so is AccessRight-Management. and many more. how about? marie

36. Iterator Design Pattern: Large Graphs & Best Practices.    forum.hibernate.org

Hello, My app contains a root object that contains a set of 12 to 40,000 items (avg 1070). These items contain 3 small sets of 2 to 10 objects a piece. The user can navigate through the various lists, and display the results. A small set of rules can be applied to this large set of items, via a visitor pattern ...

37. Lightweight pattern, again    forum.hibernate.org

Newbie Joined: Mon Apr 05, 2004 9:33 am Posts: 2 Hello I realise the issue i am referring to has been mentioned before, and i have checked all relative docs + posts that i could find on this..but it still does not work for me - so here goes. Hibernate version=2.1.2, db=SQL server 2000, driver = BEA, using Hibernate with Spring ...

38. Design pattern for this situation    forum.hibernate.org

check out the docs on inheritance. Typically when you have a userType field, in my opinion, it calls for inheritance. Hibernate can easily handle creating different types based on a user field. However, if you are stuck with a particular data model, it may not do quite what you want. Hibernate only uses a "type" field in the db, when there ...

39. WrongClassException with lightweight pattern    forum.hibernate.org

Hi, First of all I would like to say that hibernate is a superb framework and we have been using it for a while now with great success. Thank you for that! Now we have encountered some problems, that probably are of our own fault, and because our specific requirements. Maybe somebody out there have som suggestions on a solution. We ...

40. Usage Pattern    forum.hibernate.org

41. ThreadLocal Pattern question    forum.hibernate.org

I think I must be missing something basic - my apologies in advance. I have started using Hibernate with the ThreadLocal session pattern for a read-only Struts based application. A user submits a query, gets a session, gets results, and then returns to do another search. The problem is that everytime the same user searches, a new session is created and ...

42. New patterns on the blog.    forum.hibernate.org

43. AuditInfo pattern not working    forum.hibernate.org

I posted a comment to the AuditInfo pattern page ( http://www.hibernate.org/48.html ), transcribed below. The problem is I implemented that pattern and got a different behavior to the stated there. When entering in the onFlushDirty event, I receive the 'entity' object filled with AuditInfo data, and when entering onSave event, in the line: AuditInfo ai = ((Auditable) entity).getAuditInfo(); the outcome of ...

44. Question about the patterns    forum.hibernate.org

45. Are Hibernate Objs thread safe using ThreadLocal pattern ?    forum.hibernate.org

Hi rcnavarro, Glad to get a reply, OK the session is isolated. What I concern is the objects that query by this isolated session, are they thread safe too? Let's assume I have a User object mapped with DB user table. in the user object I make a hashMap as a member variable. If this user object is thread safe, I ...

47. design pattern for a read only object    forum.hibernate.org

I have the following Hibernate persisted objects. Note: PersistentObject takes care of common persisting chores (uid, discriminator, version, timestamps)... class Language extends PersistentObject { HashMap entries_; // one-to-many hash map of entry key and entry instance o } class LanguageEntry extends PersistentObject { String key; String translation; Language owner; // many-to-one } I have other classes that reference a Language. class ...

48. Design pattern question ?    forum.hibernate.org

49. Pattern for NonUniqueObjectException    forum.hibernate.org

Hibernate version: 2.1 Hibernate is working properly.. I'm looking for a pattern to apply in this case. Situation: I have a service receiving a transient, updated copy of an object called Host. If certain fields are changed on the Host then there are dependent fields on other objects that will be updated to reflect the change**. Obviously determining whether or not ...

50. lazy, web, pattern    forum.hibernate.org

hi, i just realized i'm very often facing repeating problem, maybe someone has suggestions on any pattern to solve it... suppose there is part of web application where user browses data of some object (and related objects). the view is spawned on several pages (kind of workflow). the object being browsed is loaded on start of the browsing and is being ...

51. Error in ThreadLocal Pattern    forum.hibernate.org

52. Design pattern for implementing source of unique values    forum.hibernate.org

I have following class: public class MyData implements Serializable { private Long id; private Long number; private Long category; private String text; // + getters and setters } The id property is mapped as ID in the mapping file (native generator). I would additionally set number property using some generator, which value must be unique for particular category value. What is ...

53. J2EE (anti)patterns    forum.hibernate.org

I am evaluating Hib3 for a project in a bank. We have huge volumns of data. Persistence is done through stored procedures. Business logic resides on the app server. I was reading the FAQ where you said [quote][b]I could write an essay about why common J2EE (anti)patterns which encourage the growth of parallel class hierarchies (eg. Value Objects, DAO) are inconsistent ...

54. Hibernate and Design pattern    forum.hibernate.org

55. Hibernate breaks Template Method pattern?    forum.hibernate.org

Newbie Joined: Fri Oct 07, 2005 6:36 am Posts: 7 Hello there, I'm rather new to Hibernate (and absolutely to the forums here) but I already spent a lot of time on it and a major application is already running powered by Hibernate - but I'm experiencing some error that I cannot seem to be able to solve without changing my ...

56. Pattern of Interface Oriented Programming with Hibernate?    forum.hibernate.org

When using Interface Oriented Programming, most object is referenced by interface. Let me start with a simple example: Say we have two interface and two implementing classes, they are in a one-to-one relationship. Husband, Wife, HusbandImp, WifeImp public interface Husband{ Wife getWife(); } public interface Wife{ Husband getHusband(); } public class HusbandImp implements Husband{ public Wife getWife(){ return _wife; } private ...

57. Feature Suggestion: Automated Applicaiton of Audit Patterns    forum.hibernate.org

Disclaimer: A possible 'enhancement request' for Hibernate came up in a discussion the other day, but I have not had time to think through all the issues to decide if it made sense or not. So, rather than clutter JIRA with a nebulous idea, I thought it woud be more appropriate to post it to a forum for discussion. Let me ...

58. Patterns for working with StaleObjectStateException    forum.hibernate.org

Using this exception (StaleObjectStateException), we might show the user of the second application transaction an error message (You have been working with stale data because another user modified it!) and let the first commit win. Alternatively, we could catch the exception and show the second user a new screen, allowing the user to manually merge changes between the two versions.

59. Is ThreadLocal pattern *really* thread safe?    forum.hibernate.org

60. Question with long conversation pattern    forum.hibernate.org

61. ThreadLocal pattern question under WebSphere.    forum.hibernate.org

Regular Joined: Tue Mar 21, 2006 11:01 am Posts: 65 Billy Newport, of IBM recommends against the use of ThreadLocal with WebSphere: [url]http://www.devwebsphere.com/devwebsphere/2005/06/dont_use_thread.html [/url] As a comment to this article, Gavin King of Hibernate points out that Hibernate does not use ThreadLocal, which is true. But Hibernate certainly advocates the use of ThreadLocal by its users, for example, in the CaveatEmptor ...

62. problem using ThreadLocal pattern....    forum.hibernate.org

63. Question on ThreadLocal Pattern    forum.hibernate.org

Author Message craig1980 Post subject: Question on ThreadLocal Pattern Posted: Fri Jun 23, 2006 4:00 am Newbie Joined: Wed May 24, 2006 5:47 pm Posts: 14 Hi all. I'ld like to do a question.. I have tried to use the ThreadLocal Pattern in my application. I have written this Java class: Code: import org.apache.log4j.Logger; import it.eng.hibernate.exception.DBSessionException; import it.eng.hibernate.exception.TransactionException; import ...

64. advanced long tx pattern with redirects vs. forwards    forum.hibernate.org

I started using the long application tx. pattern a while ago and am now starting to understand enough to ask a few detailed questions I can't find elsewhere. I believe the redirect functionality does not work too well with this pattern. First take a look at two scenarios. One is the forward 1. Request comes in through filter, hibernate session starts ...

65. Pattern/Best Practice    forum.hibernate.org

If you do your update of the parent in the same session as it was loaded, so you still have a valid, proxied set of contacts, then you shouldn't have to force a load of the contacts. Hibernate should know that the set isn't dirty, and thus it shouldn't try to update it. I don't think that this works for bags ...

66. J2EE patterns    forum.hibernate.org

67. ThreadLocal Pattern with Standalone Application    forum.hibernate.org

Hello, I'm using Hibernate (using a caveatemptor style DAO pattern), in a standalone application. In my application there are TCP connections which remain open for a considerable amount of time to clients (hours at a time). If I demarcate the transaction boundary at the thread level, will the data not be persisted until the connection (and thus terminating the connection thread) ...

68. design patterns from book    forum.hibernate.org

69. Hibernate patterns help needed    forum.hibernate.org

70. Improved Thread Local Pattern - Q    forum.hibernate.org

From the caller perspective he always gets an Ownership object and calls that closeSession with that identity as a parameter. For instance if the transaction flow is like Container1Servlet1----> Container1EJB1(M1-TXRequiresNew) ----> Container1EJB1(M2-TXRequired) , then both Container1EJB1(M1) and Container1EJB1(M2) will call the open session and close session at the beginning and end of the methods respectively. But the actual open will happen ...

71. Help with Listener Pattern    forum.hibernate.org

Wondering how other people have solved this issue. Let's take the Item/Bid example from the HIA book. Let's say we want to add a new feature to the system: 1. bidders are automatically notified when the item description is updated. 2. bidders can automatically withdraw their bid when the description is updated. One way to solve this is to use the ...

72. Command pattern to avoid LazyInitializationException    forum.hibernate.org

Has any one implemented command pattern to lazy load object associations and collections in 3-tier application using command pattern? I have referred the book "Java Persistence with Hibernate". It will be great if you can refer me to an working example. In my application, presentation tier access business/data tier via a proxy. So I can't use a OSIV (Open Session In ...

73. Design patterns    forum.hibernate.org

74. Repeat pattern    forum.hibernate.org

Hi,, I've this model Object --> Repeat pattern For example, I've an object with associated collections, and I need to repeat this object (change 2 o more properties) with its associated collections. Object 1 Object 2 - Property 1 - Property 1 - Property 2 - Property 2bis (this is modified) - Association 1 - Association 1 (MAny to one) - ...

75. Pattern - May i instantiate a Domain object in Presentation    forum.hibernate.org

bigtrip wrote: I have a doubt, is anti-pattern instantiate a Domain Object in Presentation Layer and fill the object than pass to Service Layer? It depends on your personal view, and of course of your architecture. If you have a rich Java client it would be a wast of ressources if you were doubling all your domain objects into so called ...

76. Patterns for non-web application...    forum.hibernate.org

Hi, I'm currently working on a batch/job processing application using JPA (Hibernate) and EJBs and I was wondering if there was existing patterns to manage transaction demarcation and lazy initialization exception problem... Currently all of my DAO are stateless EJBs and it works great until you need to access a lazy collection... I've implemented the Command pattern as suggested in Java ...