Results 1 to 4 of 4

Thread: Can JPA Annotation prop value support placeholder

  1. #1
    Join Date
    Apr 2009
    Posts
    4

    Default Can JPA Annotation prop value support placeholder

    Web all know Spring xml conf file support the prop placeholder,just like :

    <contextroperty-placeholder location="classpath:my.properties" />.
    <bean id="test" class="com.xxx.SampleClass">
    <property name="prop1" value="${my.prop1}">
    </bean>

    I use the Hibernate orm and use jpa annotion to conf the entity bean,just like :

    @Entity
    @Table(name="EMPLOYEE",schema="user_bask_sys")
    public class Employee implements Serializable {
    ...
    }


    In the example ,all the JPA annotion's prop must be plain string,so my question is coming :
    the table's schema is not static,it can be change in the delpoyment stage,
    So I holp the schema prop be setten like this:

    @Entity
    @Table(name="EMPLOYEE",schema="${user_bask_sys}")
    public class Employee implements Serializable {
    ...
    }


    the ${user_bask_sys} reference to a out prop file.

    But as I know ,the hibernate engine can't support this style conf,I Know can Spring's org.springframework.orm.hibernate.annotation.Annot ationSessionFactoryBean
    dosen't support this style ?

    So my question is can I support this placeholder annotion style throngh extend the AnnotationSessionFactoryBean myself.

    can anybody tell me can I get it and how can I get it,thanks a lot !!!

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    It isn't going to work, neither with plain hibenate or with spring. You cannot replace placeholders at runtime in compiled classes...

    You can however set the default.schema property with a placeholder.

    Code:
    <bean id="sessionFactory" class="LocalSessionFactoryBean">
     .. other properties ..
     <property name="hibernateProperties">
      <value>
        hibernate.default_schema=${user_bask_sys}
      <value>
     </property>
    </bean>
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Apr 2009
    Posts
    4

    Default to Marten Deinum

    thank you for your reply!!

    If the app only has one db schema,your approach will be work.but my app

    has more than one db schema,all the schema names must be configurable,

    so the default schema property of hibernate get into trouble.

  4. #4
    Join Date
    Oct 2009
    Posts
    16

    Default Followup

    Hi, I have a similar situation where I need to externalize the schema name used in the @Table annotation. Did you ever resolve this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •