Seeya K
Seeya K

Reputation: 1331

Blob datatype in service.xml of liferay

I am working with liferay and want to store images in my MySQL database. My service.xml goes like this:

<entity name="DLApp" local-service="true" remote-service="true">
    <column name="blobId" type="long" primary="true" />
    <column name="desc" type="String" />
    <column name="image" type="Blob" />
</entity>

When i build services I get BUILD SUCCESSFUL message but an error in package com.test.blob.upload in the blobuploadModelImpl class.

How should I write function to store image in database and retrieve it?

Upvotes: 2

Views: 1611

Answers (2)

asifaftab87
asifaftab87

Reputation: 1443

Suppose my entity name is SB_Claims so I generally get an error in SB_ClaimsModelImpl.java class

     sb_ClaimsModelImpl._ContentBlobModel = null;

sb_ClaimsModelImpl variable is not declared or defined. We just declared this variable after sevice build operation. If you build service again then this code will remove by service builder. Always this code after service build and then do not build the service just deploy your portlet. This will resolve the issue. In below I just modify that class.

    @Override
    public void resetOriginalValues() 
    {
SB_ClaimsModelImpl sb_ClaimsModelImpl=this;
sb_ClaimsModelImpl._ContentBlobModel = null;
     }

Hope this will helpful for someone.

Upvotes: 0

Pavlo Butenko
Pavlo Butenko

Reputation: 594

I had same issue with Blob, so I changed it to String type, it was enought to store images up to 10 MB as string, I have used MySql as database and those column was mapped as LONGTEXT. Also field should be 'hinted' in model hints as CLOB, See example below.

<entity name="UserExt" local-service="true" remote-service="true">
    <column name="photo" type="String" />
</entity>

<model-hints>
    <model name="com.project.model.UserExt">
                <field name="photo" type="String">
            <hint-collection name="CLOB" />
        </field>
       </model>
</model-hints>

Alternativelly you can store your images to Liferay's image gallery.

Upvotes: 1

Related Questions