Announcement Announcement Module
Collapse
No announcement yet.
Can JPA Annotation prop value support placeholder Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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>

    Comment


    • #3
      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.

      Comment


      • #4
        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?

        Comment

        Working...
        X