<openjpa-2.1.1-r422266:1148538 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Attempt to cast instance "...EntityItem@bbef5e8" to PersistenceCapable failed.  Ensure that it has been enhanced.

FailedObject: ...EntityItem@bbef5e8

at org.apache.openjpa.kernel.BrokerImpl.assertPersistenceCapable(BrokerImpl.java:4631)

at org.apache.openjpa.kernel.BrokerImpl.persistInternal(BrokerImpl.java:2610)

at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2555)

at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2538)

at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2442)

at org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1077)

at org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:715)

...

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)



[해결책]

persistence.xml 에 Item들을 추가하세요.

저작자 표시
Posted by 허니몬

관련 사이트 : http://simple.sourceforge.net/home.php


자바를 위한 XML 직렬화처리 및 설정을 해주는 높은 성능의 프레임워크다.

- Simple framework with powerful capabilities

- Can handle cycles in the object graph

- It requires absolutely no configuration

- Extremely rapid development with XML

- Converts to and from human editable XML

- Contains an XML templating system


위의 특징을 가지고 있는 프레임워크다. 자세한 내용은 사이트에 가서 확인하기 바란다.

아래 튜토리얼을 확인하기 바란다.

tutorial : http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php



간단한 예제코드

1. 먼저 Simple framework를 다운로드 받는다.

< Example.java >

  
package javastudy.simplexml;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

@Root
public class Example {
    
    @Element
    private String text;
    
    @Attribute
    private int index;

    public Example() {
        super();
    }

    public Example(String text, int index) {
        super();
        this.text = text;
        this.index = index;
    }

    public String getText() {
        return text;
    }

    public int getIndex() {
        return index;
    }
    
}

<SimpleXmlTest.java> 테스트 코드

  
package javastudy.simplexml;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import java.io.File;

import org.junit.Test;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

/**
 * simple Xml serialization 프레임워크를 이용하여 객체를 XML로 변환처리 테스트
 * @author 허니몬
 * 
 * 고려사항 : 
 *  1. Java 객체를 우선 정의해줘야한다.
 */
public class SimpleXmlTest {

    /**
     * Example 클래스의 구조를 example.xml으로 변환하여 xml파일을 생성한다.
     * 이때, 객체 안에 담겨있는 데이터는 @Attribute @Element 애노테이션에 
     * 의해 xml의 attribute와 element로 정의된다. 
     */
    @Test
    public void simpleObjectToXmlTest() {
        Serializer serializer = new Persister();
        Example example = new Example("Example message", 123);
        File result = new File("example.xml");
        
        try {
            serializer.write(example, result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    @Test
    public void simpleXmlToObjectTest() {
        Serializer serializer = new Persister();
        File source = new File("example.xml");
        
        Example example = null;
        try {
            example = serializer.read(Example.class, source);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        assertThat(example.getText(), is("Example message"));
        assertThat(example.getIndex(), is(123));
    }
}


<example.xml> 위의 코드에서 생성된 xml

  

   Example message


의 형태를 띄게 된다. 그 이외의 상세한 내용에 대해서는...

차근차근 해보도록 하자. 요즘 머리에 주입되는 정보들을 처리하느라 힘들다.




사용용도 : 객체(Java source)를 뼈대로 해서 xml파일을 생성하려고 할 때 사용할 수 있을 것이며,

이렇게 생성된 XML에 담긴 정보를 객체에 주입할여 인스턴스를 생성할 수 있을 것이다.


저작자 표시
Posted by 허니몬

참고 사이트 : 

http://struts.apache.org/2.2.3/docs/struts-2-maven-archetypes.html


  메이븐을 이용하면 의존성을 가진 라이브러리들까지 손쉽게 다운로드 받아서 프로젝트를 생성할 수가 있다.

  2줄의 명령어만 넣어주면 된다.


스트럿츠 archetype을 생성하는 방법은 두 종류가 있다. 둘 중 마음에 드는 방법을 선택한다.


1.1. 메이븐의 archetype을 이용하여 스트럿츠 프로젝트를 생성(generate)한다.

  - 스트럿츠 2.2.3.1 버전을 사용했다. 

mvn archetype:generate -B
-DgroupId=tutorial
-DartifactId=tutorial
-DarchetypeGroupId=org.apache.struts
-DarchetypeArtifactId=struts2-archetype-blank

-DarchetypeVersion=<version>


1.2. 스트럿츠 archetype 을 생성한다. 
mvn archetype:generate -DarchetypeCatalog=http://struts.apache.org/

2. 메이븐으로 생성한 프로젝트를 이클립스에서 사용할 수 있는 프로젝트로 변경한다.

mvn eclipse:eclipse -Dwtpversion=1.5
이렇게 하면 된다. 
그럼 이클립스에서 사용할 수 있는 프로젝트가 간단하게 생성된다. 

1.2번과 2번을 같이하는 게... 편한 것 같기도 하다.


생성 과정 기록 : 


HoneyBook:dreaminfra ihoneymon$ mvn archetype:generate -DarchetypeCatalog=http://struts.apache.org/

[INFO] Scanning for projects...

[INFO]                                                                         

[INFO] ------------------------------------------------------------------------

[INFO] Building Maven Stub Project (No POM) 1

[INFO] ------------------------------------------------------------------------

[INFO] 

[INFO] >>> maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom >>>

[INFO] 

[INFO] <<< maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom <<<

[INFO] 

[INFO] --- maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom ---

[INFO] Generating project in Interactive mode

[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)

//원하는 유형을 선택하고 groupId, articleId 를 임의에 따라 지정한다.

Choose archetype:

1: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-blank (Struts 2 Archetypes - Blank)

2: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-convention (Struts 2 Archetypes - Blank Convention)

3: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-dbportlet (Struts 2 Archetypes - Database Portlet)

4: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-plugin (Struts 2 Archetypes - Plugin)

5: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-portlet (Struts 2 Archetypes - Portlet)

6: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-starter (Struts 2 Archetypes - Starter)

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1

Define value for property 'groupId': : StudyStruts

Define value for property 'artifactId': : StudyStruts

Define value for property 'version':  1.0-SNAPSHOT: : 

Define value for property 'package':  StudyStruts: : 

Confirm properties configuration:

groupId: StudyStruts

artifactId: StudyStruts

version: 1.0-SNAPSHOT

package: StudyStruts

 Y: : y

[INFO] ----------------------------------------------------------------------------

[INFO] Using following parameters for creating project from Archetype: struts2-archetype-blank:2.2.1

[INFO] ----------------------------------------------------------------------------

[INFO] Parameter: groupId, Value: StudyStruts

[INFO] Parameter: artifactId, Value: StudyStruts

[INFO] Parameter: version, Value: 1.0-SNAPSHOT

[INFO] Parameter: package, Value: StudyStruts

[INFO] Parameter: packageInPathFormat, Value: StudyStruts

[INFO] Parameter: package, Value: StudyStruts

[INFO] Parameter: version, Value: 1.0-SNAPSHOT

[INFO] Parameter: groupId, Value: StudyStruts

[INFO] Parameter: artifactId, Value: StudyStruts

[INFO] project created from Archetype in dir: /Users/ihoneymon/Documents/workspaces/dreaminfra/StudyStruts

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 15.347s

[INFO] Finished at: Wed Oct 12 10:45:18 KST 2011

[INFO] Final Memory: 7M/81M

[INFO] ------------------------------------------------------------------------

HoneyBook:dreaminfra ihoneymon$ cd StudyStruts/

HoneyBook:StudyStruts ihoneymon$ mvn eclipse:eclipse -Dwtpversion=1.5

[INFO] Scanning for projects...

[INFO]                                                                         

[INFO] ------------------------------------------------------------------------

[INFO] Building Struts 2 Blank Webapp 1.0-SNAPSHOT

[INFO] ------------------------------------------------------------------------

[INFO] 

[INFO] >>> maven-eclipse-plugin:2.8:eclipse (default-cli) @ StudyStruts >>>

[INFO] 

[INFO] <<< maven-eclipse-plugin:2.8:eclipse (default-cli) @ StudyStruts <<<

[INFO] 

[INFO] --- maven-eclipse-plugin:2.8:eclipse (default-cli) @ StudyStruts ---

[INFO] Adding support for WTP version 1.5.

[INFO] Using Eclipse Workspace: /Users/ihoneymon/Documents/workspaces/dreaminfra

[WARNING] Workspace defines a VM that does not contain a valid jre/lib/rt.jar: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

[INFO] no substring wtp server match.

[INFO] Using as WTP server : VMware vFabric tc Server Developer Edition (Runtime) v2.5

[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER

[INFO] Not writing settings - defaults suffice

[INFO] Wrote Eclipse project for "StudyStruts" to /Users/ihoneymon/Documents/workspaces/dreaminfra/StudyStruts.

[INFO] 

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 2.254s

[INFO] Finished at: Wed Oct 12 10:45:34 KST 2011

[INFO] Final Memory: 6M/81M

[INFO] ------------------------------------------------------------------------

HoneyBook:StudyStruts ihoneymon$ 

이클립스를 열고, 이 StudyStruts라는 폴더를 import하면 스트럿츠 라이브러리가 설치된 프로젝트를 바로 이용해볼 수 있다. 여기에는 간단한 예제 코드가 포함되어 있다. 이 프로젝트를 서버에 추가하고 실행해보면 다음처럼 나온다.

자! 스트럿츠를 시작해보자.

저작자 표시
Posted by 허니몬

파일명 : config.properties

property.thisReadUrl=/app/test/show



파일명 : testFreemarker.ftl

<#list "${props['property.thisReadUrl']}"?split(",") as url>

    <#if (RawRequest.requestURI?index_of((url!)?trim) == -1)>

구현내용 ~~~~

    </#if>

</#list>

** RawRequest.requestURI 는 http RAW Request 정보를 가져오는 것 같은데, 이 부분에 대해서는 공부할 필요가 있겠다

기능 : 현재 URL 위치를 반환한다.


위의 형태처럼 ${props['properties']} 를 이용하여 서버에 적용된 properties 들을 조회하여 동일한 이름을 가진 property를 freemarker 파일을 구성하는 과정에서 사용할 수가 있다.


이를 위해서는 applicationContext.xml 내에 



    
         
            properties 파일 위치
        
         
    



에 대한 내용들을 설정해줘야 한다. 


저작자 표시
Posted by 허니몬
IBatis 가 가동되기 전, 서브 SqlMap에 있는 XML들을  읽는다.
이때 SqlmapXxxx.xml에 있는 ResultMap 과 해당하는 클래스의 Mapping 확인도 진행된다.

이런 메시지가 뜬다면, 
 Caused by: com.ibatis.common.beans.ProbeException: There is no WRITEABLE property named 'leadDay' in class '...domain.showcase.bestseller.BestSellerList'
해당하는 sqlmap에서 <ResultMap>에서 class property에 설정된 클래스와 <result> 내에 property 항목이 일치하는지  확인하도록 한다.
저작자 표시
Posted by 허니몬
이전버튼 1 2 3 4 이전버튼