Have you just created an ASP.Net MVC project from scratch? You didn't like the default namespace because Visual Studio just applies the name of the project. So, you change the namespace in the project properties, and your classes now have a nice looking namespace.
You run the debugger to take full stock of your beautiful application and this is what you get:
So, you hunt around your application, and, maybe, you find some of the default namespaces hanging around. After making the appropriate changes, you run the debugger, again. And, still, this error persists. What gives?
Look here: Views/web.config. You'll find the default namespace. In my example, "LargeDachshund" is my default namespace, but I changed it to "com.BlogSpot.LargeDachshund" in my code. Well, everywhere except here:
So change the namespace to your newly adopted version, and you're in business!
Woof!
This blog is dedicated to those that have helped me gain technical expertise and make a living. You make the world a better place.
Friday, October 9, 2015
Friday, August 7, 2015
Hibernate Red Herring #2315: @Version and the Transient Object Exception
I have a class, PitchingStat, that looks like this:
@Entity
@Table(name="PitchingStat", schema="hotDogs")
public class PitchingStat{ @Id
@Column(name="id")
private long id; @Column(name="player_id", nullable=false)
private int playerId; @Column(name="strikeOuts")
private int strikeOuts; @ManyToOne
@JoinColumn(name="player_id", referencedColumnName="player_id")
private MLBPlayer mlbPlayer .
.
.
} It has a parent class nested in it, MLBPlayer. @Entity
@Table(name="MLBPlayer", schema="hotDogs")
public class MLBPlayer{ @Id
@Column(name="player_id")
private int playerId; @Column(name="created")
private Date created; @Column(name="createdBy")
private String createdBy; @Version
private long version; .
.
.
} If you implemented @Version, as I did, after the MLBPlayer table had been created and populated with data, then it's possible that you have encountered the transient object exception. Much of the MLBPlayer table's version column might have null values in some of the records. While this may seem innocuous at first blush, you obviously haven't worked with this Hibernate gem. I attempted to save the PitchingStat object like this: assume this MLBPitchingStat record is linked to an MLBPlayer record that has version = null.
MLBPitchingStat pitchingStat = getMLBPitchingStatByIdFromDb(pitchingSession, Id); pitchingStat.setStrikeOuts(34); pitchingSession.saveOrUpdate(pitchingStat); Wham! Transient Object Exception: You need to save this transient entity, MLBPlayer, prior to saving the current object. What happened? Apparently Hibernate has a fit over the version column's null value in the database. The version needs to be set in MLBPlayer, prior to saving the child record, MLBPitchingStat. So how do you go about resolving this? Try this:
MLBPitchingStat pitchingStat = getMLBPitchingStatByIdFromDb(pitchingSession, Id); pitchingStat.setStrikeOuts(34); MLBPlayer mlbPlayer = pitchingStat.getMLBPlayer(); mlbPlayer.setVersion(1L); pitchingStat.setMLBPlayer(mlbPlayer); pitchingSession.saveOrUpdate(pitchingStat); Now, you would think this would work. Wrong! Hibernate still has that fit over the version column's null value in the database. So what's the answer? Do this:
In your database:
Update MLBPlayer as p
set p.version = 1
where p.version is null; Problem solved. Woof!
@Table(name="PitchingStat", schema="hotDogs")
public class PitchingStat{ @Id
@Column(name="id")
private long id; @Column(name="player_id", nullable=false)
private int playerId; @Column(name="strikeOuts")
private int strikeOuts; @ManyToOne
@JoinColumn(name="player_id", referencedColumnName="player_id")
private MLBPlayer mlbPlayer .
.
.
} It has a parent class nested in it, MLBPlayer. @Entity
@Table(name="MLBPlayer", schema="hotDogs")
public class MLBPlayer{ @Id
@Column(name="player_id")
private int playerId; @Column(name="created")
private Date created; @Column(name="createdBy")
private String createdBy; @Version
private long version; .
.
.
} If you implemented @Version, as I did, after the MLBPlayer table had been created and populated with data, then it's possible that you have encountered the transient object exception. Much of the MLBPlayer table's version column might have null values in some of the records. While this may seem innocuous at first blush, you obviously haven't worked with this Hibernate gem. I attempted to save the PitchingStat object like this: assume this MLBPitchingStat record is linked to an MLBPlayer record that has version = null.
MLBPitchingStat pitchingStat = getMLBPitchingStatByIdFromDb(pitchingSession, Id); pitchingStat.setStrikeOuts(34); pitchingSession.saveOrUpdate(pitchingStat); Wham! Transient Object Exception: You need to save this transient entity, MLBPlayer, prior to saving the current object. What happened? Apparently Hibernate has a fit over the version column's null value in the database. The version needs to be set in MLBPlayer, prior to saving the child record, MLBPitchingStat. So how do you go about resolving this? Try this:
MLBPitchingStat pitchingStat = getMLBPitchingStatByIdFromDb(pitchingSession, Id); pitchingStat.setStrikeOuts(34); MLBPlayer mlbPlayer = pitchingStat.getMLBPlayer(); mlbPlayer.setVersion(1L); pitchingStat.setMLBPlayer(mlbPlayer); pitchingSession.saveOrUpdate(pitchingStat); Now, you would think this would work. Wrong! Hibernate still has that fit over the version column's null value in the database. So what's the answer? Do this:
In your database:
Update MLBPlayer as p
set p.version = 1
where p.version is null; Problem solved. Woof!
Thursday, June 18, 2015
Tomcat Logging: a Lesson in Half-Baked
Out of the box, Tomcat logging will output to catalina.out, until your hard drive is brought to its knees. We won't hold our breath for the day that logrotate is implemented natively on those files in the logs folder.
Instead, here's how to logrotate that pesky catalina.out file.
1. In your Tomcat, navigate to .../bin/catalina.sh
2. Within catalina.sh, search for this keyword: "catalina.out"
3. Now, by default, catalina.out will be set to "CATALINA_BASE"\logs\catalina.out
4. LogRotate can't seem to operate in Tomcat's logs folder. So, let's move the file somewhere else. Let's say, /var/log/tomcat, for example.
5. Next, let's configure a logrotate file that cron will operate on.
6. Navigate to /etc/logrotate.d
7. Create the file, "tomcat" and add the following configuration:
Based on this configuration, cron will copy and truncate the catalina.out file daily. logrotate will keep seven days worth of catalina.out logs
8. Let's save out a catalina.out file: sudo vi /var/log/tomcat/catalina.out
9. To make things more user friendly, let's put a symbolic link in Tomcat's logs folder
10. Navigate to Tomcat's logs folder
11. Then: sudo ln -s /var/log/tomcat/catalina.out catalina.out
12. Finally, for all of this to take effect, we'll need to restart Tomcat
13. So, sudo ../bin/shutdown.sh
14. Then ../bin/startup.sh
Please note, cron has it's own notion when it'll perform the logrotate. My system performs the operation at 3am.
Instead, here's how to logrotate that pesky catalina.out file.
1. In your Tomcat, navigate to .../bin/catalina.sh
2. Within catalina.sh, search for this keyword: "catalina.out"
3. Now, by default, catalina.out will be set to "CATALINA_BASE"\logs\catalina.out
4. LogRotate can't seem to operate in Tomcat's logs folder. So, let's move the file somewhere else. Let's say, /var/log/tomcat, for example.
5. Next, let's configure a logrotate file that cron will operate on.
6. Navigate to /etc/logrotate.d
7. Create the file, "tomcat" and add the following configuration:
Based on this configuration, cron will copy and truncate the catalina.out file daily. logrotate will keep seven days worth of catalina.out logs
8. Let's save out a catalina.out file: sudo vi /var/log/tomcat/catalina.out
9. To make things more user friendly, let's put a symbolic link in Tomcat's logs folder
10. Navigate to Tomcat's logs folder
11. Then: sudo ln -s /var/log/tomcat/catalina.out catalina.out
12. Finally, for all of this to take effect, we'll need to restart Tomcat
13. So, sudo ../bin/shutdown.sh
14. Then ../bin/startup.sh
Please note, cron has it's own notion when it'll perform the logrotate. My system performs the operation at 3am.
Labels:
catalina.out,
catalina.sh,
copytruncate,
logrotate,
logs,
tomcat
Subscribe to:
Comments (Atom)