Announcement

Collapse
No announcement yet.

Entity Bean - Setter-Methode schreibt null Werte in Datenbank

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Entity Bean - Setter-Methode schreibt null Werte in Datenbank

    Hallo zusammen

    Seit einigen Tagen schlage ich mich mit einem äußerst merkwürdigen Problem herum.

    Eine Enitity Bean "PlayerGroupBean" soll Objekte vom Typ "PlayerGroupVO" persistieren. Beim Aufruf der entsprechenden set-Methode wird jedoch nichts in die Datenbank eingetragen. Ein späteres Auslesen des Objektes aus der Datenbank würde 'null' zurückliefern. Weder in der Konsole, noch im Server-Log ist zu erkennen, was schief gelaufen ist.

    Das Deployment der Bean läuft ohne Fehler. Auch alle weiteren set-Methoden der Bean funktionieren. Dass PlayerGroupVO zum Zeitpunkt des Aufrufs 'null' ist, kann ausgeschlossen werden, da kurz zuvor noch Werte aus dem Objekt ausgelesen werden und es zu keiner NPE kommt.

    Ich verwende JBoss 4.2 und eine PostgreSQL Datenbank. Die Bean wurde mit EJB 2.1 entwickelt. Sie wurde aus einer bestehenden Anwendung als Altlast übernommen und soll in absehbarer Zeit auch nicht auf EJB 3 migriert werden.

    Anbei ein Auszug aus der Bean-Implementierung.

    Code:
    /**
     * <p>
     * A PlayerGroup is associated with at least one or multiple players and
     * associated with a leaf scope of the game tree.
     * </p>
     * 
     * <p>
     * The primary-key of this view is composedNamePK, which is created using the
     * gameRealPK and the scopePathPK. The primary key isn't changeable.
     * </p>
     * 
     * @author Christian Arndt
     * @version 1.0
     * @ejb.bean name="PlayerGroup" type="CMP" cmp-version="2.x" view-type="local"
     *           primkey-field = "composedNamePK" jndi-name="ejb/PlayerGroup"
     *           local-jndi-name="ejb/PlayerGroup" schema="PlayerGroup"
     * 
     * @ejb.finder unchecked = "true" signature = "java.util.Collection findAll()"
     *             query = "SELECT OBJECT(p) FROM PlayerGroup AS p"
     *             
     * @ejb.finder unchecked = "true" signature = "model.entity.lif.PlayerGroupLocal
     *             findByNameAndGameRealPK(java.lang.String gameRealNamePK, 
     *             java.lang.String namePK)" query="select object(o) from PlayerGroup as o 
     *             where o.gameRealPK=?1 AND o.name=?2"
     * 
     * @ejb.permission role-name = "admin, sysAdmin, player, cactusRole, ejbTimeout"
     */
    public abstract class PlayerGroupBean implements EntityBean {
    
    	transient private final Logger logger = Logger.getLogger(PlayerGroupBean.class);
    
    	/**
    	 * <p>
    	 * This constructor creates a new player-group-instance. It checks for
    	 * duplicate primary keys and throws, if he founds a player-group having the
    	 * same primary key, a <code>DuplicatePKException</code>.
    	 * </p>
    	 * 
    	 * @ejb.create-method
    	 */
    	public String ejbCreate(GameLocal game, String gameRealPK, String scopePath)
    			throws CreateException {
    		logger.debug("entered ejbCreate for playerGroupVO with gameRealPK=" + gameRealPK
    				+ " and  scopePath=" + scopePath + ")");
    
    		final String composedNamePK = createComposedNamePK(
    				game.getRealNamePK(), scopePath.toString());
    
    		setComposedNamePK(composedNamePK);
    		setScopePath(scopePath);
    		setGameRealPK(gameRealPK);
    		
    		logger.info("storing new playerGroup in database");
    		return null;
    	}
    
    	/**
    	 * This post constructor sets the CMR Relationship game. *
    	 */
    	public void ejbPostCreate(GameLocal game, PlayerGroupVO playerGroupVO) {
    		final String gameRealPK = playerGroupVO.getScope().getGame().getRealNamePK();
    		final String scopePath = playerGroupVO.getScope().toString();
    		
    		logger.debug("entered ejbPostCreate for playerGroupVO with gameRealPK=" + gameRealPK
    				+ " and  scopePath=" + scopePath + ")");
    		setGame(game);
    		logger.debug("link to game established");
    	}
    
    	public void ejbRemove() throws RemoveException {
    		PlayerLocal player;
    		try {
    			final Object[] playerArray = getPlayers().toArray();
    			for (int i = 0; i < playerArray.length; i++) {
    				player = (PlayerLocal) playerArray[i];
    				logger.debug("removing player with namePK="
    						+ player.getNamePK());
    				player.remove();
    			}
    		} catch (final RemoveException re) {
    			logger.debug("Counldn't remove Player-entry!");
    			throw new RemoveException("Counldn't remove Player-entry! "
    					+ re.getMessage());
    		}
    	}
    
    	/**
    	 * Getter for the CMP Field playerGroupVO.
    	 * 
    	 * @ejb.interface-method
    	 * @ejb.persistence
    	 */
    	public abstract PlayerGroupVO getPlayerGroupVO();
    
    	/**
    	 * Setter for the CMP Field playerGroupVO.
    	 * 
    	 * @ejb.interface-method
    	 */
    	public abstract void setPlayerGroupVO(PlayerGroupVO playerGroup);
    	
    }
    Deployment Deskriptor ejb-jar.xml (Auszug)
    Code:
    <ejb-name>PlayerGroup</ejb-name>
    
             <local-home>model.entity.lif.PlayerGroupLocalHome</local-home>
             <local>model.entity.lif.PlayerGroupLocal</local>
    
             <ejb-class>model.entity.cmp.PlayerGroupCMP</ejb-class>
             <persistence-type>Container</persistence-type>
             <prim-key-class>java.lang.String</prim-key-class>
             <reentrant>False</reentrant>
             <cmp-version>2.x</cmp-version>
             <abstract-schema-name>PlayerGroup</abstract-schema-name>
             <cmp-field >
                <description><![CDATA[Getter for the CMP PK-Field composedNamePK]]></description>
                <field-name>composedNamePK</field-name>
             </cmp-field>
             <cmp-field >
                <description><![CDATA[Getter for the CMP Field gameRealPK.]]></description>
                <field-name>gameRealPK</field-name>
             </cmp-field>
             <cmp-field >
                <description><![CDATA[Getter for the CMP Field groupNotes.]]></description>
                <field-name>groupNotes</field-name>
             </cmp-field>
             <cmp-field >
                <description><![CDATA[Getter for the CMP Field name.]]></description>
                <field-name>name</field-name>
             </cmp-field>
             <cmp-field >
                <description><![CDATA[Getter for the CMP Field playerGroupVO.]]></description>
                <field-name>playerGroupVO</field-name>
             </cmp-field>
             <cmp-field >
                <description><![CDATA[Getter for the CMP Field scopePath.]]></description>
                <field-name>scopePath</field-name>
             </cmp-field>
             <primkey-field>composedNamePK</primkey-field>
    
             <query>
                <query-method>
                   <method-name>findAll</method-name>
                   <method-params>
                   </method-params>
                </query-method>
                <ejb-ql><![CDATA[SELECT OBJECT(p) FROM PlayerGroup AS p]]></ejb-ql>
             </query>
             <query>
                <query-method>
                   <method-name>findByNameAndGameRealPK</method-name>
                   <method-params>
                      <method-param>java.lang.String</method-param>
                      <method-param>java.lang.String</method-param>
                   </method-params>
                </query-method>
                <ejb-ql><![CDATA[select object(o) from PlayerGroup as o where o.gameRealPK=?1 AND o.name=?2]]></ejb-ql>
             </query>
             <query>
                <description><![CDATA[Finder method to select the form for the given gameRealPK, the given scopePathPK and the given turn number from database.]]></description>
                <query-method>
                   <method-name>ejbSelectFormByTurn</method-name>
                   <method-params>
                      <method-param>java.lang.String</method-param>
                      <method-param>java.lang.String</method-param>
                      <method-param>int</method-param>
                   </method-params>
                </query-method>
                <ejb-ql><![CDATA[select object(o) from Form as o where o.gameRealPK=?1 and o.scopePathPK=?2 and o.turnNrPK=?3]]></ejb-ql>
             </query>
             <query>
                <description><![CDATA[Finder method to select the report for the given gameRealPK, the given scopePathPK and the given turn number from database.]]></description>
                <query-method>
                   <method-name>ejbSelectReportByTurn</method-name>
                   <method-params>
                      <method-param>java.lang.String</method-param>
                      <method-param>java.lang.String</method-param>
                      <method-param>int</method-param>
                   </method-params>
                </query-method>
                <ejb-ql><![CDATA[select object(o) from Report as o where o.gameRealPK=?1 and o.scopePathPK=?2 and o.turnNrPK=?3]]></ejb-ql>
             </query>
    	  <!-- Write a file named ejb-finders-PlayerGroupBean.xml if you want to define extra finders. -->
    
          </entity>
    Deployment Deskriptor jbosscmp-jdbc.xml (Auszug)
    Code:
    <entity>
             <ejb-name>PlayerGroup</ejb-name>
    
             <cmp-field>
                <field-name>composedNamePK</field-name>
    
            </cmp-field>
             <cmp-field>
                <field-name>gameRealPK</field-name>
    
            </cmp-field>
             <cmp-field>
                <field-name>groupNotes</field-name>
    
            </cmp-field>
             <cmp-field>
                <field-name>name</field-name>
    
            </cmp-field>
             <cmp-field>
                <field-name>playerGroupVO</field-name>
    
            </cmp-field>
             <cmp-field>
                <field-name>scopePath</field-name>
    
            </cmp-field>
    Auszug aus dem Lokal Interface (durch Xdoclet generiert).
    Code:
    public interface PlayerGroupLocal
       extends javax.ejb.EJBLocalObject
    {
      /**
        * Getter for the CMP Field playerGroupVO.
        */
       public model.voAndLogic.core.PlayerGroupVO getPlayerGroupVO(  ) ;
    
      /**
        * Setter for the CMP Field playerGroupVO.
        */
       public void setPlayerGroupVO( model.voAndLogic.core.PlayerGroupVO playerGroup ) ;   
    }
    Vielleicht hat jemand eine Idee, woran es liegen könnte oder mit einem ähnlichen Fehler bereits Erfahrungen gemacht.

    Ich bin für jeden Hinweis dankbar.

    Christian
Working...
X