001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.persistence.kernel;
020:
021: import java.io.Serializable;
022: import javax.persistence.CascadeType;
023: import javax.persistence.Entity;
024: import javax.persistence.EntityManager;
025: import javax.persistence.Id;
026: import javax.persistence.OneToOne;
027: import javax.persistence.Table;
028:
029: import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
030:
031: public class TestEJBNoPersistentFields extends AbstractTestCase {
032:
033: private Nholder holder;
034:
035: public TestEJBNoPersistentFields(String test) {
036: super (test, "kernelcactusapp");
037: }
038:
039: public void setUp() throws Exception {
040: deleteAll(Nholder.class);
041: }
042:
043: public void testNoPersistentFields() {
044: EntityManager em = currentEntityManager();
045: startTx(em);
046:
047: holder = new Nholder();
048: holder.setNpf(new NoPersistentFieldsPC());
049: holder.setIdKey(1);
050:
051: em.persist(holder);
052: endTx(em);
053:
054: Nholder holder2 = em.find(Nholder.class, 1);
055: assertEquals(1, holder2.getIdKey());
056: assertNotNull(holder2);
057: assertNotNull(holder2.getNpf());
058:
059: endEm(em);
060: }
061:
062: @SuppressWarnings("serial")
063: @Entity
064: @Table(name="nholder2")
065: public static class Nholder implements Serializable {
066:
067: @Id
068: private int idkey;
069:
070: @OneToOne(cascade={CascadeType.PERSIST,CascadeType.REMOVE})
071: private NoPersistentFieldsPC npf;
072:
073: public Nholder() {
074: }
075:
076: public Nholder(NoPersistentFieldsPC npf, int idkey) {
077: this .npf = npf;
078: this .idkey = idkey;
079: }
080:
081: public void setNpf(NoPersistentFieldsPC npf) {
082: this .npf = npf;
083: }
084:
085: public NoPersistentFieldsPC getNpf() {
086: return this .npf;
087: }
088:
089: public int getIdKey() {
090: return idkey;
091: }
092:
093: public void setIdKey(int idkey) {
094: this .idkey = idkey;
095: }
096: }
097:
098: @SuppressWarnings("serial")
099: @Entity
100: @Table(name="npfp")
101: public static class NoPersistentFieldsPC implements Serializable {
102:
103: public transient int blankInt;
104: public transient String blankString;
105: }
106: }
|