You are talking about Arbeitnehmererfindungen and those only belong to the employer if they are created on company time or if they are related to the work (Diensterfindung) every other invention belongs to the inventor (freie Erfindung) see §18 arbnerfg (3) althought you have to submit the invention to your employer if it could be related to the work (1-2)
https://www.gesetze-im-internet.de/arbnerfg/BJNR007560957.ht...
Yes, plenty of countries have bizarrely unfair laws.
(edit: it appears that the law in Germany is not as bad as initially presented by the parent comment).
The solution is to just make it explicit to your employer / manager what you’re doing, and save the emails / documents.
Just imagine the complete breakdown if a group of employees actually tried to go through with that: every wacky idea, from self-lacing shoes ("seem something similar in a movie") to bipedal gigawatt wind turbines that walk off to windier locations in a lull ("stomp, stomp, stomp! awesome!"). If they have to tell, some poor soul must be obliged to listen!
I did a little googling and it seems, that if you patent something that benefits your company, they can license it from you, and if they patent something you invent, then they have to pay you a revenue share. If they try and fuck you after a disclosure, then you get to keep the patent.
(Edit: couldn't find it in the law, and will not be in the University library soon to check the legal commentaries — but I still find that question interesting)
That may sound bizarrely unfair to you, but elsewhere (Germany) it's actually the law (but only for inventions/patents, not other IP).
The employee has to tell the employer about any patentable idea, even if not in the general field of his employment, and even if having occurred after hours.
The employer can then either claim the patent (but has to pay something), or he can release the invention (and the employee can patent it on his own).