Archiv für Kategorie Computer & Technik

Twitter und Blog-Updates

Winter in Wuppertal (Uellendahl)

Winter am Uellendahl

Ich habe mal wieder etwas Zeit gefunden, im Blog aufzuräumen. Einige Plugin-Updates und das WordPress-Update auf 2.6.3 wurden installiert.
Außerdem habe ich mich bei Twitter angemeldet, und texte jetzt auch fleißig was mir gerade so ein-, auf- oder missfällt. Die jeweils drei letzten Tweets finden sich auch hier im Blog in der Seitenleiste.

Zu guter letzt habe ich das Schneewetter gestern abend in Wuppertal und heute in Münster genutzt und einen Haufen Fotos gemacht. Zu sehen in meinem Account bei Flickr.

, , , ,

Keine Kommentare

How to get rid of “Could not resolve a persistence unit corresponding to the persistence-context-ref-name …” exceptions

One error that's been bugging me since I started out using Spring together with JPA in a Glassfish Application Server was an exception such as the following:

com.sun.enterprise.deployment.backend.IASDeploymentException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [de.icanmakeit.jpokerstats.jpa.dao.GameDao/_entityManager] in the scope of the module called [jpokerstats]. Please verify your application.

The core problem here is that the mentioned GameDao uses the @PersistenceContext annotation to obtain an EntityManager from the container (or in this case Spring) but there are multiple persistence units defined in the persistence.xml (for the live system, for testing, etc.) and the Glassfish is unable to decide to which of these persistence units the annotation should be mapped.

Since I wanted all of this to be managed by Spring, I didn't bother this error and worked around it by downgrading the web.xml from 2.5 to 2.4 which disabled the J5EE dependency injection mechanism in Glassfish and let Spring do its job. Simply specifying @PersistenceContext(unitName="myunit") wasn't an option, since the same classes use a different persistence unit during JUnit tests and on the live server and explicitly specifying a persistence unit name breaks the unit tests.

Since my "inner ITIL" requires a developing solution after finding a workaround, I searched around the net, read a couple of dozen forum posts and finally figured out a way to solve the problem (...which I could have done earlier if I only had read the complete J5EE specification... *yawn*).

When deploying a 2.5 web application to Glassfish, the server examines it for any dependency injection annotations such as @PersistenceContext. It generates a default name for any unnamed annotation by using the FQCN, appended with a slash and the name of the field/property that is the injection target. In the above example, this would result in the name de.icanmakeit.jpokerstats.jpa.dao.GameDao/_entityManager. The server then tries find a persistence unit reference for this name. If there is only one persistence unit defined, this one will be used, otherwise the deployment descriptors are checked for configuration hints.

So in order to solve this problem, we have to provided these configuration hints. Adding the following few lines to the web.xml solves the problem:

XML:
  1. <persistence-context-ref>
  2.     <persistence-context-ref-name>de.icanmakeit.jpokerstats.jpa.dao.GameDao/_entityManager</persistence-context-ref-name>
  3.     <persistence-unit-name>pokerstats_live</persistence-unit-name>
  4. </persistence-context-ref>

This approach has one major drawback: if your software contains more than one @PersistenceContext injection target, you have to define a persistence-context-ref for each occurrence. This situation can be avoided by naming each @PersistenceContext annotation and giving them all the same name (note: the correct attribute is name, not unitName):

JAVA:
  1. @PersistenceContext(name="pokerstats")
  2. private EntityManager _entityManager;

All injection target with the same annotation name can now share a single persistence-context-ref (you can also use this name to look up the persistence unit using JNDI):

XML:
  1. <persistence-context-ref>
  2.     <persistence-context-ref-name>pokerstats</persistence-context-ref-name>
  3.     <persistence-unit-name>pokerstats_live</persistence-unit-name>
  4. </persistence-context-ref>

Update: Below you'll find the relevant parts of the Spring configuration file for the example above. It defines two beans, the first one makes the datasource, that has been configured in the Glassfish Server, available for use in Spring. The second one defines the entity manager factory that Spring will use to support the JPA context.

XML:
  1. <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
  2.     <property name="jndiName" value="jdbc/__pokerstats"/>
  3. </bean>
  4.  
  5. <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  6.     <property name="dataSource" ref="dataSource"/>
  7.     <property name="persistenceUnitName" value="pokerstats_live"/>
  8.     <property name="loadTimeWeaver">
  9.         <bean class="org.springframework.instrument.classloading.glassfish.GlassFishLoadTimeWeaver"/>
  10.     </property>
  11.     <property name="persistenceProvider">
  12.         <bean class="oracle.toplink.essentials.PersistenceProvider"/>
  13.     </property>
  14. </bean>

, , , , , , ,

4 Kommentare

Unsensibler Umgang mit sensiblen Informationen

Wie heißt es so schön? Die Frage ist nicht, ob Du paranoid bist, die Frage ist: bis Du paranoid genug? Man muss nicht übermäßig paranoid sein, um seine sensiblen Informationen zu schützen. Leider sind viele Zeitgenossen diesbezüglich sehr unsensibel und gehen äußerst freizügig mit Informationen um, die außer ihnen niemand kennen sollte.

Zwei Beispiele: Der Zugangscode zum Mitarbeiterbereich der Deutschen Bahn im Hauptbahnhof Münster lautet 9033. Woher ich das weiß? Es ist nicht so, dass ich es drauf angelegt hätte, ihn in Erfahrung zu bringen. Aber die meisten Bediensteten, die da ein- und ausgehen tippen den Code einfach lustlos vor aller Leute Augen ein. Man muss schon wegsehen, um den Code nicht zu erfahren. Ich hoffe mal, der Code rotiert täglich.

Das andere Beispiel: Mein Kollege Bodo hat im Rahmen seiner Tätigkeit für den TV-Browser ein Angebot für ein Serverhosting bekommen, um den Downloadtraffic besser stemmen zu können. Der Betreiber, der ihm den Server zur Verfügung gestellt hat, hat die unendlich schwer zu erratende Benutzername/Passwort-Kombination bestehend aus dem Produktnamen und dem Namen meines Kollegen für den Zugang gewählt.

Hat denn niemand von Bruce Schneider, Kevin Mitnick oder anderen gelernt?

,

1 Kommentar

Linux als Massenbetriebssystem

Ich weiß, der Witz mit dem Symlink-auf-ein-Verzeichnis-löschen ist alt, aber so lange man unter Linux immer noch solche Meldungen bekommt, wirds nichts mit dem Massenmarkt:

BASH:
  1. [BuschH@cobra-bay jpokerstats]$ sudo rm stats/
  2. rm: Entfernen von "stats/" nicht möglich: Ist ein Verzeichnis
  3. [BuschH@cobra-bay jpokerstats]$ sudo rm -rf stats/
  4. rm: Entfernen von Verzeichnis "stats/" nicht möglich: Ist kein Verzeichnis

,

Keine Kommentare

Geheimakte 2: Puritas Cordis – In-Game Gags

Nachdem ich vor etwas mehr als einem Jahr das Adventure Geheimakte Tunguska durchgespielt habe und damit sehr zufrieden war, war es nur logisch, sich auch die Fortsetzung, Puritas Cordis zuzulegen. Wer sich das Spiel selber mal ansehen möchte, kann sich die Demo runterladen.

Jetzt gehts aber mal nicht um das Spiel an sich, sondern um die interessanten kleinen Gags in dem Spiel, die mir bisher aufgefallen sind und die mit zur humoristischen Unternote beitragen, mit der sich die Entwickler verewigt haben. Da die Beschreibung evtl. ein paar Spoiler enthält, gibts die Gags erst durch einen Klick auf "mehr".

Zum Rest des Beitrags »

, , , ,

Keine Kommentare