Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    JPA2DataSource exclude fields question

    Hi,

    I cannot figure out how to exclude some fields for either validation or serialization. I tried to set dropExtraFields but it didn't work.

    Code:
    <DataSource ID="usersDS"
            serverConstructor="com.isomorphic.jpa.JPA2DataSource"   
            schemaBean="cz.bcom.smartrise.server.persistence.hibernate.UsrUsers"
            dropExtraFields="true">  
    	<fields>
    1) when I try to add a new user it leads to a VALIDATION_E because ID field is missing. ID gets generated by a database trigger on insert.

    Code:
    	@Id
    	@GeneratedValue(strategy = IDENTITY)
    	@Column(name = "ID", unique = true, nullable = false)
    	public Integer getId() {
    		return this.id;
    	}
    2) I have a field pwd which is mandatory in the entity. It holds encripted password. I don't want this field to send over at all.
    I defined a new field in the ds.xml password which acts as plain text password field.
    In DMI I used to convert password field into pwd.

    What would be the best way to achieve this?

    3)
    Another field I don't want to send across is byte[] which can be large. It holds *.PDF files.

    4) Ideally, I'd like to send over and validate only fields which I explicitly defined in ds.xml The same way it works for DMI data sources.

    I set some fields just before add or update. for example I set who made a last change on the object. Those fields are mandatory on the entity but they shouldn't be set on the GUI.

    best regards,
    Zdary

    #2
    dropExtraFields="true" will prevent fields being delivered to the client *if you do not declared them in your dataSource". As far as #1, this sounds like you've declared the field as required="true", but an auto-generated field should not be declared this way (the user does not need to enter a value, which is what "required" means).

    Comment


      #3
      Hi,

      in the end I found out that my DS was misconfigured.
      dropExtraFields is ignored when schemaBean is defined.

      I defined schemaBean instead of beanClassName.

      The solution is
      Code:
      <DataSource ID="usersDS"
              serverConstructor="com.isomorphic.jpa.JPA2DataSource"   
              beanClassName="cz.bcom.smartrise.server.persistence.hibernate.UsrUsers"
              dropExtraFields="true">
      best regards,
      Zdary

      Comment


        #4
        To clarify:
        dropExtraFields is not ignored.
        When you define schemaBean all mapped fields are declared in data source.
        Fields can not be dropped, because they are declared.

        Alius.

        Comment


          #5
          I see, that makes sence.

          thank you

          Comment

          Working...
          X