[ 
https://issues.apache.org/jira/browse/RAVE-678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13295649#comment-13295649
 ] 

Anne-Hélène TURPIN commented on RAVE-678:
-----------------------------------------

1) Create a custom Category : 

package fr.renater.portal.model; 

@Entity 
@NamedQueries({ @NamedQuery(name = Category.GET_CATEGORY_BY_KEYWORD_IN_DESC, 
query = "select c from Category c where lower(c.description) like :keyword") }) 
public class Category extends org.apache.rave.portal.model.Category implements 
BasicEntity, Serializable { 

  private static final long serialVersionUID = 1L; 
  public static final String GET_CATEGORY_BY_KEYWORD_IN_DESC = 
"Category.getCategoryByKeywordInDesc"; 
  public static final String KEYWORD_PARAM = "keyword"; 

  @Basic 
  @Column(name = "description") 
  @Lob 
  private String description; 
.... 

2) Create a new repository interface : 

package fr.renater.portal.repository; 

public interface CategoryRenaterRepository { 

  /** 
  * Finds the list of category for a given keyword 
  * @param keyword the keyword of the category description to find category for 
  * @return a valid List of category that are contain the keyword on the 
description 
  */
  List<fr.renater.portal.model.Category> getCategoryByKeywordInDesc(String 
keyword);
 ... 

3) Create a new repository implementation class : 

package fr.renater.portal.repository.impl; 

@Repository(value="categoryRepository") 
@Primary 
@Transactional 
public class CategoryRenaterRepositoryImpl extends 
org.apache.rave.portal.repository.impl.JpaCategoryRepository implements 
CategoryRenaterRepository { 

  @PersistenceContext 
  private EntityManager manager;

  @Override 
  public List<fr.renater.portal.model.Category> 
getCategoryByKeywordInDesc(String keyword) {  
     TypedQuery<fr.renater.portal.model.Category> category = 
manager.createNamedQuery(fr.renater.portal.model.Category.GET_CATEGORY_BY_KEYWORD_IN_DESC,
 fr.renater.portal.model.Category.class); 
    category.setParameter(fr.renater.portal.model.Category.KEYWORD_PARAM, 
"%"+keyword.trim().toLowerCase()+"%"); 
    return category.getResultList(); 
  } 
  .... 

4) Overlay core-applicationContext.xml with our version that includes component 
scans of our custom packages. 

5) Create a test class : 

@Transactional 
@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations = {"classpath:test-dataContext.xml", 
"classpath:test-applicationContext.xml"}) 
public class CategoryRenaterRepositoryTest { 

  private static final String TEXT1 = "Technology"; 
  private static final String TEXT2 = "Communications"; 

 @Resource(name="categoryRepository") 
  private CategoryRenaterRepository repository; 

 @Test 
  public void getCategoryByKeywordInDesc() { 
     List<fr.renater.portal.model.Category> list = 
repository.getCategoryByKeywordInDesc("computer"); 
     assertThat(list.size(), is(2)); 
     assertThat(list.get(0).getText(), is(equalTo(TEXT1))); 
     assertThat(list.get(1).getText(), is(equalTo(TEXT2))); 
  } 
... 

If the attributes are private in the Category class, I have this error : 

<openjpa-2.1.1-r422266:1148538 fatal general error> 
org.apache.openjpa.persistence.PersistenceException: Column "T0.ID" not found; 
SQL statement: SELECT t0.id, t0.description FROM Category t0 WHERE 
(LOWER(t0.description) LIKE ? ESCAPE '\') [42122-154] {SELECT t0.id, 
t0.description FROM Category t0 WHERE (LOWER(t0.description) LIKE ? ESCAPE 
'\')} [code=42122, state=42S22] FailedObject: select c from Category c where 
lower(c.description) like :keyword [java.lang.String] 
                
> Change model's attributes in protected
> --------------------------------------
>
>                 Key: RAVE-678
>                 URL: https://issues.apache.org/jira/browse/RAVE-678
>             Project: Rave
>          Issue Type: Improvement
>          Components: rave-core
>            Reporter: Anne-Hélène TURPIN
>         Attachments: NewPage.java
>
>
> We would like to extend the rave model persistence. We would like to inherit 
> attributes from the superclass but It's impossible except for the Person 
> model which has protected attributes.
> Is it possible to modify it for models in the rave-core component and in the 
> rave-opensocial-core component ?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to